Start a docker container on CentOS at boot time as a linux service

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


ExecStart=/usr/bin/docker start my_container_name
ExecStop=/usr/bin/docker stop my_container_name


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.



This entry was posted in docker, linux. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s