On my CentOS 7.2 box, with Docker 1.10.3, I successfully tested the following (running as root):
docker run --name usljavadoc_server -p 80:80 -p 443:443 -v /opt/app/uslJavadoc/:/var/www/html/ -d eboraas/apache
Content automatically deployed to
/opt/app/uslJavadoc was servable from the apache running in the container.
So, my next step was getting this to work with systemd, so I created
/etc/systemd/system/docker-usljavadoc.service with the following contents:
[Unit] Description=Apache serving USL Javadoc Requires=docker.service After=docker.service [Service] TimeoutStartSec=0 Restart=always ExecStart=/usr/bin/docker run --name usljavadoc_server -p 80:80 -p 443:443 -v /opt/app/uslJavadoc/:/var/www/html/ -d eboraas/apache ExecStop=/usr/bin/docker stop -t 2 usljavadoc_server ExecStopPost=/usr/bin/docker rm -f usljavadoc_server [Install] WantedBy=default.target
I manually reloaded systemd and started the service. I verified that the browser on another box could reach the apache process and get the properly served content. I then rebooted to make sure it works on reboot. Still worked.
So, I thought I was done. However, what I noticed when I looked closer is that the service successfully starts, but it exits immediately after starting, and then restarts. This is happening continuously. As it's just plain html content being served (a javadoc tree), and that the service immediately restarts, users might not even notice there is a problem, but it definitely shouldn't be doing this.
Any ideas why this "docker run" works fine from the shell, and seems to start fine from systemd, but exits immediately after a couple of seconds?