How to restart start a docker container from commandline?

How to restart a docker container from commandline?

The docker command provides many options and one of them enables us to restart a container.

How to restart a running docker container?

[vamshi@node01 ~]$ docker restart jenkins_master01
jenkins_master01

We can set a wait timer using the -t[number in seconds] flag:

[vamshi@node01 ~]$ docker  restart -t20 jenkins_master01
[root@node01 ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                 NAMES
c86791fad19c        jenkins             "/bin/tini -- /usr..."   42 minutes ago      Up 6 seconds        8080/tcp, 50000/tcp   jenkins_master01

How to start a docker container?

# docker start <container-id | container-name>

We look at a practical example, listing out the exited container as follows:

[vamshi@node01 ~]$ docker ps -f status="exited"  | grep jenkins -B1
CONTAINER ID        IMAGE                                        COMMAND                  CREATED             STATUS                     PORTS               NAMES
b511234ebe31        rrskris/jenkins                            "/bin/tini -- /usr..."   3 weeks ago         Exited (143) 1 day ago                       jenkins_master01

We now will start the container back live as follows:

[vamshi@node01 ~]$ docker start b511234ebe31 
b511234ebe31
It did not complain and lets check the running status again now:
[vamshi@node01 ~]$ docker ps -f status="running"  | grep jenkins -B1
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                 NAMES
b511234ebe31        rrskris/jenkins   "/bin/tini -- /usr..."   3 weeks ago         Up 9 minutes        8080/tcp, 50000/tcp   jenkins_master01

It did start alright and carried on the same old name and preserved its old state

Leave a Comment