I have an amazon EC2 instance running RedHat 7, with docker service installed and enabled. I need a particular container to be started at boot time.
I have done this by installing a service which runs after the docker service is executed.
Note: If docker daemon does not start at boot, you might want to enable the docker service
systemctl enable docker.service
Here are the steps.
Create the file /etc/systemd/system/docker_demo_container.service
[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
systemctl start docker_demo_container
And I can enable the service so it is executed at boot
systemctl enable docker_demo_container
That’s it, my container is started at boot.
Also take a look at related docker documentation.