Docker Restart and Rename

docker container restart

This command restarts one or more containers.

Syntax

docker restart [OPTIONS] CONTAINER [CONTAINER...]

Options

--time, -t: Seconds to wait for a stop before killing the container, Default value is 10 sec

Restarting a single container

learning-ocean:~ gaurav$ docker container restart 615
615

Restarting all containers

learning-ocean:~ gaurav$ docker restart $(docker ps -a -q)

Rename Docker Container

docker rename

The docker rename command renames a container.

docker rename CONTAINER NEW_NAME
docker rename old_container new_container

In the example below, we have renames a container starting with ID bc from thirsty_dijkstra to nginx-container

learning-ocean:~ gaurav$ docker container ls
CONTAINER ID   IMAGE          COMMAND                  CREATED             STATUS          PORTS        NAMES
bc2cb9f905ff   nginx          "/docker-entrypoint.…"   18 minutes ago      Up 18 minutes   80/tcp       thirsty_dijkstra

learning-ocean:~ gaurav$ docker container rename bc nginx-container

learning-ocean:~ gaurav$ docker container ls
CONTAINER ID   IMAGE          COMMAND                  CREATED             STATUS          PORTS        NAMES
bc2cb9f905ff   nginx          "/docker-entrypoint.…"   19 minutes ago      Up 19 minutes   80/tcp       nginx-container
learning-ocean:~ gaurav$