title: Running Docker Compose with Docker description: Running Docker Compose on a Container-Optimized OS instance. author: tswast tags: Docker,Docker Compose,Container-Optimized OS,Compute Engine date_published: 2017-05-03
- Run Docker Compose with Docker on Container-Optimized OS.
- Create an alias for the containerized
Before you begin
- Create or select a Cloud Platform project from the Google Cloud Platform console's projects page.
- Enable billing for your project.
This tutorial uses billable components of Cloud Platform including
Use the Pricing Calculator to estimate the costs for your usage.
Setting up the virtual machine
Create a new Compute Engine instance using the Container-Optimized OS stable image.
- Open the Google Cloud Platform console.
- Create a new Compute Engine instance.
- Select the desired Zone, such as "us-central1-f".
- Select the desired Machine type, such as "micro" (f1-micro).
- Change the Boot disk to "Container-Optimized OS stable".
- Check the box to allow HTTP traffic in the Firewall section.
- Click the Create button to create the Compute Engine instance.
Getting the sample code
- After the instance is created, click the SSH button to open a terminal connected to the machine.
Download the Hello World sample using the
git clone https://github.com/docker/dockercloud-hello-world.git cd dockercloud-hello-world
Running Docker Compose
Container-Optimized OS has many benefits, but since it is locked down by default, it is difficult to run software that is not bundled in a container. For example, the general instructions for installing Docker Compose will not work because very few parts of the filesystem are mounted as executable. Instead, you can run Docker Compose image.
Download and run the Docker Compose image. Check the tags for Docker Compose to use the latest version.
docker run docker/compose:1.13.0 version
Run the Docker Compose command to run the sample code.
So that the Docker Compose container has access to the Docker daemon, mount the Docker socket with the
To make the current directory available to the container, use the
-v "$PWD:/rootfs/$PWD"option to mount it as a volume and the
-w="/rootfs/$PWD"to change the working directory.
docker run \ -v /var/run/docker.sock:/var/run/docker.sock \ -v "$PWD:/rootfs/$PWD" \ -w="/rootfs/$PWD" \ docker/compose:1.13.0 up
docker runcommand still running, open the Google Cloud Platform Console instances page. Click the link to your instance's External IP address.
You should see a "Hello World" message appear.
With the SSH window open, press Control-C on your keyboard to stop the sample application.
Making an alias to Docker Compose
docker run ... docker/compose:1.13.0 up command is equivalent to running
docker-compose up command on systems where Docker Compose is installed by
the usual method. So that you don't have to remember or type this long command,
create an alias for it.
docker-composealias to your shell configuration file, e.g.
echo alias docker-compose="'"'docker run \ -v /var/run/docker.sock:/var/run/docker.sock \ -v "$PWD:/rootfs/$PWD" \ -w="/rootfs/$PWD" \ docker/compose:1.13.0'"'" >> ~/.bashrc
Reload the Bash configuration.
Change back to the sample directory if you aren't already there.
Run the sample code using the new
You should be able to view the "Hello World" message at your instance's external IP address.
- Set up the Google Cloud logging driver for Docker to upload your containers' logs to Stackdriver Logging.
- Use CoreOS Toolbox to run other tools in the Container-Optimized OS.
- Learn how to orchestrate containers using Kubernetes. Use Kompose to transform Docker Compose configuration into Kubernetes manifests.