| 1 | = Docker HowTo Auto Start Containers On Reboot |
| 2 | |
| 3 | An explanation for systemd as a process manager can be found at : |
| 4 | |
| 5 | {{{https://docs.docker.com/engine/admin/host_integration/}}} |
| 6 | |
| 7 | Once you are happy with your docker images and container, you must us systemd to restart them. |
| 8 | |
| 9 | 1. Go to the directory : |
| 10 | |
| 11 | {{{/etc/systemd/system}}} |
| 12 | |
| 13 | This directory contains all .service files that are used to start docker containers. |
| 14 | |
| 15 | 2. Check what docker services are enabled on start up |
| 16 | |
| 17 | {{{systemctl list-unit-files | grep docker}}} |
| 18 | |
| 19 | This will list out all the services that are enabled. |
| 20 | |
| 21 | 3a. To create a new service called *docker-[containername].service* : |
| 22 | |
| 23 | {{{sudo vi /etc/systemd/system/docker-redcap_5.7.0.service}}} |
| 24 | |
| 25 | add the contents : |
| 26 | |
| 27 | {{{[Unit]}}} |
| 28 | {{{Description=Redcap 5.7.0 container}}} |
| 29 | {{{Requires=docker.service}}} |
| 30 | {{{After=docker.service}}} |
| 31 | {{{ }}} |
| 32 | {{{[Service]}}} |
| 33 | {{{Restart=always}}} |
| 34 | {{{ExecStart=/usr/bin/docker run -itd -p 81:80 lcbruit/redcap:v1}}} |
| 35 | {{{ExecStop=/usr/bin/docker stop -t 2 lcbruit/redcap:v1}}} |
| 36 | {{{ }}} |
| 37 | {{{[Install]}}} |
| 38 | {{{WantedBy=default.target}}} |
| 39 | |
| 40 | 3b. To amend |
| 41 | |
| 42 | Run the following : |
| 43 | |
| 44 | {{{systemctl daemon-reload}}} |
| 45 | {{{systemctl start docker-redcap_5.7.0.service}}} |
| 46 | {{{systemctl enable docker-redcap_5.7.0.service}}} |