RequirementsThe environment for the tutorial is based on the following requirements for UrbanCode Deploy and Docker. IBM UrbanCode Deploy v6.2 or higher with a configured agent to communicate with a Docker engine is required. Additionally, the Docker Compose client interface must be installed on the UrbanCode Deploy agent machine. Before you continue, verify that the server, agent, and Docker components are configured. The latest version of the following IBM UrbanCode Deploy plug-ins must be installed. To download the latest version of a plug-in, click the name of the plug-in. The link takes you to the plug-in page where you can download the plug-in.
- Docker Application Template
- Docker Compose Template
- Docker Template
docker-compose.ymlfile that describes your application. For this tutorial, download the YAML file here and place it in a directory accessible by your IBM UrbanCode Deploy agent.
Simple Docker Compose WordPress TutorialFirst, create a component to represent the Docker Compose application using the Docker Compose Template component template that was installed during setup. This component holds the Docker Compose YAML file as a component version and also provides a Docker Compose Launch component process. Below is a screenshot of my configuration settings for my Docker WordPress Tutorial component.
There are a few properties to note in my configuration settings above.
- The default value for the Docker Compose File Path field is
docker-compose.yml. It can be left unchanged. This is the only artifact that the component maintains.
- The Source Configuration Type field is a matter of preference. Placing your YAML files in source control is a good practice. For this tutorial, I used the value:
File System (Versioned)and enabled the Import Versions Automatically option. Note: you can also use the udclient tool. Whichever choice you make, the YAML file is needed in a component version, so that it can be downloaded to the working directory in our processes. Below is an example of what the component version artifacts should look like (the YAML file at the top-level).
Let’s take a moment now to view the component process provided by the Docker Compose Template component template. In your new component, browse to the Processes tab and click the Docker Compose Launch component process. This launches the component process editor. The Docker Compose Launch component process is an all-in-one deployment flow to:
- Retrieve the necessary Compose YAML
- Include configuration logic to point to different Docker engines or swarms
- Pull the necessary Docker images
docker-compose upto build your application.
- Download Artifacts. Retrieves
docker-compose.ymlfrom CodeStation and downloads the file to the working directory
- Create Child Resources. This is a multi-functional step provided by the Docker Compose plug-in
- Creates new components with the compose.service tag based on the services specified in the YAML
- Creates component resources for new components as child resources of the original Docker Compose component
- Enables version overrides when launching the Docker Compose application so users can specify versions aside from what’s in the YAML file
- Launch Docker Compose Application. Runs
docker-compose up -dwith the original YAML file plus any overrides that you specified
After the plug-in steps complete, the component is ready. Note: If your Docker engine is not located with the agent or you are targeting Docker Swarm, you need to pass additional options to the docker-compose client interface to target the correct Docker runtime. This can be accomplished using resource properties in several ways. In the Launch Docker Compose Application step, you must do one of the following:
- Specify the environment variables to export with the Environment Property Values field (hidden), such as
DOCKER_HOST, DOCKER_CERT_PATH, and
- Specify a script to execute using the Environment Scripts Path field
- Pass runtime switches using the Additional Options field
Defining the WordPress applicationReturn to component listing and notice that the new component is labeled with a Docker-Compose tag. The default color for this tag is green. If it is not labeled, you must assign it manually. Tags are required for creating applications when using templates in UrbanCode Deploy.
Application templates in UrbanCode Deploy include a wizard to configure new applications quickly and easily. Tags are used to specify which components are part of an application. Templates can also include processes, properties, and environment templates. Create a new application in UrbanCode Deploy called Docker WordPress Application. To create the application, click Create Application and select the Docker Application Template from the Template drop-down. The Create Application wizard includes a four-step process to create an application. Parameters in the four steps depend given by the chosen template. Step 1 defines the name of the application. Step 2 is where you specify which components to add. Only components with the required tags are displayed. For this example, select the component tagged Docker-Compose and click Continue. Step 3 defines the environments of your application. For this example, you can leave the fields on this page as-is. However, it is OK to modify the names and number of environments. Step 4 defines the agents associated with each environment. On the left, is a list of all the agents. On the right, is a list of the environments specified in the previous step. Map an agent to each environment then click Save. When the wizard completes, you can view the new application. Below is a graphic showing the new application. Notice that the resource hierarchies were automatically generated as shown below.
Launching the Docker Compose applicationWe can finally launch our Docker Compose application! Simply click the Process Request button on your desired environment. Specify the
Docker Compose Launchprocess and your Docker Compose component version, then click Submit. Sit back and after a few minutes, your new WordPress instance will be running on your Docker host on port 8000.
You might be wondering about the other components with the compose.service tags. Or, how do we use the version overrides feature provided by the Create Child Resources step. Unless specified otherwise, the Docker Compose Launch process uses the versions specified in the YAML file. In this tutorial, these images are wordpress:4.6 and mysql:5.7. The Create Child Resources step creates new components based on these services and also creates a version for each component to correspond with the information in the YAML file. You can setup the source configuration for these new components so that UrbanCode Deploy knows all tags for a Docker image in a registry. Then, users can specify these different versions when they request a process and the Create Child Resources step overrides the tags specified in the YAML file. In addition, enabling the feature to Import Versions Automatically ensures that new versions are available in UrbanCode Deploy with no human intervention.
Continue to repeat the deployment with different image versions to see the result, and recall that the “fpm” versions of the
library/wordpressimage on Docker Hub work a bit differently and causes issues. Feel free to leave comments or questions below.
Continue to repeat the deployment with different image versions to see the result, and recall that the “fpm” versions of the library/wordpress image on Docker Hub work a bit differently and causes issues. Feel free to leave a comment or question below.