# Auto start application using docker-compose

**URL:** <https://forums.suse.com/t/auto-start-application-using-docker-compose/1119>\
**Category:** RancherOS\
**Created:** [November 29, 2015, 4:45pm UTC](https://forums.suse.com/t/auto-start-application-using-docker-compose/1119 "2015-11-29T16:45:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![carloss](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@carloss](https://forums.suse.com/u/carloss)\
**Post date:** [November 29, 2015, 4:45pm UTC](https://forums.suse.com/t/auto-start-application-using-docker-compose/1119/1 "2015-11-29T16:45:16Z")

</div>

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 -m`sudo 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](http://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!

---

<div class="post-metadata">

**Author:** ![carloss](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@carloss](https://forums.suse.com/u/carloss)\
**Post date:** [November 29, 2015, 5:02pm UTC](https://forums.suse.com/t/auto-start-application-using-docker-compose/1119/2 "2015-11-29T17:02:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![denise](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@denise](https://forums.suse.com/u/denise)\
**Post date:** [December 1, 2015, 10:32pm UTC](https://forums.suse.com/t/auto-start-application-using-docker-compose/1119/3 "2015-12-01T22:32:48Z")

</div>

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

```auto
#cloud-config

rancher:
  services:
    service1:
      restart: always
      net: host

```

Here’s a similar issue: [Launch system service via cloud-init](http://forums.suse.com/t/launch-system-service-via-cloud-init/1129)

---

<div class="post-metadata">

**Author:** ![carloss](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@carloss](https://forums.suse.com/u/carloss)\
**Post date:** [December 2, 2015, 11:24am UTC](https://forums.suse.com/t/auto-start-application-using-docker-compose/1119/4 "2015-12-02T11:24:42Z")

</div>

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](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](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?

---

<div class="post-metadata">

**Author:** ![denise](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@denise](https://forums.suse.com/u/denise)\
**Post date:** [December 15, 2015, 10:14pm UTC](https://forums.suse.com/t/auto-start-application-using-docker-compose/1119/5 "2015-12-15T22:14:04Z")

</div>

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](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](https://github.com/rancher/os/issues/685)
