If you are a developer and responsible to manage the Docker containers life cycle, you must know all the commands of Docker which Docker offers. In this short article, I’ll explain all the commands of the Docker container with examples:

The easy way to know all the commands of the Docker container is to run the help command on the host machine where Docker is installed as follows:

[root@instance-20191018-2102 ~]# docker container --help

The above command will give all the containers commands with an explanation.

The following table, explains all the commands of the Docker’s container:

CommandDescriptionExample
attachAllow to attach local standard input, output, and error streams to a running container.docker container attach <container_id_or_name>
commitAllow to create of a new image from the container’s changes.docker container commit <container_id_or_name> <image_name>:<tag>
cpAllow to copy files/folder between the container and local file system.docker container cp <file_to_copy> <container_id_or_name>:<contanier_location_to_copy> 
createAllow to create a new container.docker container create -d <image_name>
diffAllow to insect changes to files or directories on filesystem of the container. docker container diff <container_id_or_name>
execAllow to run a command in a running container.docker container exec <container_id_or_name> cat /etc/hosts
exportAllow to export the containers filesystem as a tar file.docker container export <container_id_or_name> > name.tar
inspectAllow to inspect the detailed information of one or more containers.docker container inspect <container_id_or_name>
killAllow to kill one or more containers.docker container kill <container_id_or_name>
logsAllow to fetch the log of a container.docker container logs <container_id_or_name> 
lsAllow to list the containersdocker container ls
pauseAllow to pause the processes of one more container.docker container pause <container_id_or_name>
portAllow to list port mapping or a specific mapping for the containerdocker container port <container_id_or_name>
pruneAllow to remove all stopped containers at once.docker container prune
renameAllow to rename the container’s name.docker container rename <container_id_or_name> NEW_NAME
rmAllow to remove one or more containers.docker container rm <container_id_or_name>
runAllow to create and start the container.docker container run -d <image_name>
startAllow to start one or more containers.docker container start <container_id_or_name>
statsAllow to view the resource usage statistics of the running container.docker container stats
stopAllow to stop one or more containers.docker container stop <container_id_or_name>
topAllow to view the running process inside the container.docker container top <container_id_or_name>
unpauseAllow to unpause the processes of one or more container.docker container unpause <container_id_or_name>
updateAllow to update the configuration of one or more container.docker container update –memory 100M –memory–swap 100M <container_id_or_name>
waitAllow to block until one or more containers stop, then print their exit code.docker container wait <container_id_or_name>
restartAllow to restart one or more containers.docker container restart <container_id_or_name>

Each command of the container has various options that can be used with the command. To know the options of the run command, use the following command:

[root@instance-20191018-2102 ~]# docker container run --help

Similarly, you can view the options of other commands.

Further readings

How to create a docker container

Architecture and basic terminologies of Docker

How to create an NGINX docker container

Lifecycle of Docker container

You can subscribe to my YouTube channel for further reading.