1

I'm trying to get my container to run on startup using upstart.

As the tutorial said - I created /etc/init/nginx_server.conf

description "Nginx docker"
author "Me"
start on filesystem and started docker
stop on runlevel [!2345]
respawn
script
  /usr/bin/docker run -d -p 80:80 test_server
end script

Running of latest Amazon linux (amzn-ami-hvm-2015.03.0.x86_64-gp2)

The container isn't running at all (running docker ps -a doesn't show it at all)

10
  • Provide an actual image to the run target ? There's no test_server container in the docker registry. – Xavier Lucas May 10 '15 at 13:32
  • When I run it in command line (after the machine is up) it works. I'm not following what you are trying to say... – Boaz May 10 '15 at 13:49
  • New to docker ? What's the test_server image ? Where does this come from ? Nothing of this kind is available in the docker registry. Past your commands and their output when you do this without upstart. Past sudo docker images output and sudo docker ps -a too. – Xavier Lucas May 10 '15 at 14:08
  • It's my own local container of a locally built image – Boaz May 10 '15 at 14:54
  • 1
    Wow...Amazon Linux still uses upstart?!? – Michael Hampton May 10 '15 at 14:57
2

On Amazon Linux, the Docker daemon is started with an init.d script, not an Upstart script. In your Upstart script you're trying to signal the startup when the docker service starts (..started docker). This will only work if the docker init script is an Upstart script.

You can add initctl emit docker-started to the docker init.d script and then trigger your Upstart service config file with that event (ie. start on docker-started)

1

You cannot do a 'docker run' from the upstart, what you should do is create a container from a docker image, and then do 'docker start' in upstart. If you check /var/log/messages you will probably see something like:

init: test_server main process (6570) terminated with status 1
init: test_server respawning too fast, stopped

To work around it, try running:

docker run -d -p 80:80 test_server

You will get the container id as an output:

a64db8e1cca5

Then, put in your upstart file:

description "Nginx docker"
start on filesystem and started docker
stop on runlevel [!2345]
respawn
script
  /usr/bin/docker start -a a64db8e1cca5
end script
6
  • You can give your container a name with --name <name> when using docker run and refer to it in other subcommands instead of using the container hash ID. – Xavier Lucas May 10 '15 at 14:21
  • 1
    Yes, you can, although I answered purposely this way, that it's clearly obvious what's container and what is an image. But still thanks for the comment. – Jakov Sosic May 10 '15 at 14:24
  • Why would you not be able to issue docker run from upstart since it's basically a create + start action ? I believe you simply need to remove the -d option. – Xavier Lucas May 10 '15 at 14:43
  • wait. When I do a docker run, it stays persistent in the FS of the host? – Boaz May 10 '15 at 14:53
  • 1
    @Boaz Yes unless you pass the --rm option. – Xavier Lucas May 10 '15 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.