Note: If docker daemon does not start at boot, you might want to enable the docker service
1
|
systemctl enable docker.service |
Here are the steps.
Create the file /etc/systemd/system/docker_demo_container.service
1
2
3
4
5
6
7
8
9
10
11
|
[Unit] Wants=docker.service After=docker.service [Service] RemainAfterExit= yes ExecStart= /usr/bin/docker start my_container_name ExecStop= /usr/bin/docker stop my_container_name [Install] WantedBy=multi-user.target |
Now I can start the service
1
|
systemctl start docker_demo_container |
And I can enable the service so it is executed at boot
1
|
systemctl enable docker_demo_container |
That’s it, my container is started at boot.
[Unit] |
Description=MariaDB container |
Requires=docker.service |
After=docker.service |
[Service] |
User=php |
Restart=always |
RestartSec=10 |
# ExecStartPre=-/usr/bin/docker kill database |
# ExecStartPre=-/usr/bin/docker rm database |
ExecStart=/usr/bin/docker start -a database |
ExecStop=/usr/bin/docker stop -t 2 database |
[Install] |
WantedBy=multi-user.target
#!/bin/bash
exec "$@"
and I have the following in my Dockerfile:
ADD entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["date"]
Recent Comments