Step 1 — Installing Docker Compose
Although we can install Docker Compose from the official Ubuntu repositories, it is several minor version behind the latest release, so we’ll install Docker Compose from the Docker’s GitHub repository. The command below is slightly different than the one you’ll find on the Releases page. By using the -o flag to specify the output file first rather than redirecting the output, this syntax avoids running into a permission denied error caused when using sudo.
We’ll check the current release and if necessary, update it in the command below:
sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
Next we’ll set the permissions:
sudo chmod +x /usr/local/bin/docker-compose
Then we’ll verify that the installation was successful by checking the version:
docker-compose --versionThis will print out the version we installed:
docker-compose version 1.21.2, build a133471
Now that we have Docker Compose installed, we’re ready to run a “Hello World” example.
Step 2 — Running a Container with Docker Compose
The public Docker registry, Docker Hub, includes a Hello World image for demonstration and testing. It illustrates the minimal configuration required to run a container using Docker Compose: a YAML file that calls a single image:
First, we’ll create a directory for the YAML file and move into it:
mkdir hello-world cd hello-worldThen, we’ll create the YAML file: