docker-compose in a container

Instead of downloading and installing docker-compose, it is possible to run docker-compose within a docker container! This is handy when all that you have access to is a fixed image (like Google's Container Optimized OS, CoreOS, or Fedora Atomic). Google posted some great instructions on how to do this but here's the summary:

Run Manually

This is the equivalent to docker-compose up -d. It takes the current directory and mounts it inside the docker-compose container (so it can find docker-compose.yml and all of its dependencies).

sudo docker run -v /var/run/docker.sock:/var/run/docker.sock -v "$PWD:/rootfs/$PWD" -w "/rootfs/$PWD" docker/compose:1.21.2 up -d

Create a docker-compose shell alias

echo alias docker-compose="'"'sudo docker run -v /var/run/docker.sock:/var/run/docker.sock -v "$PWD:/rootfs/$PWD" -w "/rootfs/$PWD" docker/compose:1.21.2'"'" > ~/.bashrc

Then all you need to do is:

$ docker-compose up -d

Some cautions:

  1. Beware that because docker compose is now running in a container, it doesn't have access to the same files and paths as the host. It can mount volumes from the host no problem, but you have to specify full paths.
  2. I've hard-coded a particular version of compose above (version 1.21.2). This is good to version control and get something with functionality you expect and have tested, but it also means you may miss out on updates. Head on over to the docker compose container info page to see what the latest version is and change the above as appropriate.
  3. Depending on your docker setup, you may or may not need sudo. Feel free to drop that part.
Contact Us