Auto start application using docker-compose

Hello,

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

- path: /opt/rancher/bin/start.sh permissions: "0755" content: | #!/bin/bash if [ ! -f /opt/bin/docker-compose ]; then sudo mkdir /opt/bin sudo wget -O /opt/bin/docker-compose https://github.com/docker/compose/releases/download/1.5.1/docker-compose-uname -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 http://boot.xxx.yyy/docker-compose.www.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 start.sh 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?

#cloud-config

rancher:
  services:
    service1:
      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: https://github.com/rancher/os/issues/423
  2. possibility of using the new networking model of Docker 1.9: https://github.com/rancher/os/issues/668

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.

https://github.com/rancher/os/issues/423

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.

https://github.com/rancher/os/issues/685