Auto start application using docker-compose


I would like to start my application automatically from cloud config. I have it already like this:

- path: /opt/rancher/bin/ permissions: "0755" content: | #!/bin/bash if [ ! -f /opt/bin/docker-compose ]; then sudo mkdir /opt/bin sudo wget -O /opt/bin/docker-compose -s-uname -msudo chmod +x /opt/bin/docker-compose fi sleep 10 export V4_PRIVATE_IP=$V4_PRIVATE_IP export V4_PUBLIC_IP=$V4_PUBLIC_IP wget -q -O docker-compose.yml export COMPOSE_PROJECT_NAME=www /opt/bin/docker-compose --x-networking --x-network-driver bridge up -d >> /var/log/compose.log 2>&1

The problem is that docker is not ready until the file is fully executed! Because of that, docker-compose fails with message:

Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running? If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.

Any idea? Is there an option to auto-run some scripts at the time user docker is ready? For obvious reason I don’t want to run the app as system service.

Please help!

Adding export DOCKER_HOST=unix:///var/run/docker.sock did not help

Have you tried just adding in the docker-compose.yml information into the cloud config directly?


      restart: always
      net: host

Here’s a similar issue: Launch system service via cloud-init

I would love to launch apps by defining them in cloud config, but there are two problems preventing me to do so:

  1. authentication to Docker Hub in order to use private images:
  2. possibility of using the new networking model of Docker 1.9:

Also, if I use docker-compose manually, I can see the logs of the whole application using docker-compose -p myapp logs, which I am not sure would be possible if I bootstrap my app using the cloud config. Or is it?

I have just figured out how to authenticate to DockerHub to use private images and updated the issue.

Basically, you can write the login credentials to the directory.

But unfortunately, you cannot login and use the same cloud-config to launch services using those credentials. I’ve created an enhancement request for it.