running a docker container on upstart on Amazon Linux isn't working

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)


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)


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