Know about all commands of the Docker container
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:
Command | Description | Example |
---|---|---|
attach | Allow to attach local standard input, output, and error streams to a running container. | docker container attach <container_id_or_name> |
commit | Allow to create of a new image from the container’s changes. | docker container commit <container_id_or_name> <image_name>:<tag> |
cp | Allow 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> |
create | Allow to create a new container. | docker container create -d <image_name> |
diff | Allow to insect changes to files or directories on filesystem of the container. | docker container diff <container_id_or_name> |
exec | Allow to run a command in a running container. | docker container exec <container_id_or_name> cat /etc/hosts |
export | Allow to export the containers filesystem as a tar file. | docker container export <container_id_or_name> > name.tar |
inspect | Allow to inspect the detailed information of one or more containers. | docker container inspect <container_id_or_name> |
kill | Allow to kill one or more containers. | docker container kill <container_id_or_name> |
logs | Allow to fetch the log of a container. | docker container logs <container_id_or_name> |
ls | Allow to list the containers | docker container ls |
pause | Allow to pause the processes of one more container. | docker container pause <container_id_or_name> |
port | Allow to list port mapping or a specific mapping for the container | docker container port <container_id_or_name> |
prune | Allow to remove all stopped containers at once. | docker container prune |
rename | Allow to rename the container’s name. | docker container rename <container_id_or_name> NEW_NAME |
rm | Allow to remove one or more containers. | docker container rm <container_id_or_name> |
run | Allow to create and start the container. | docker container run -d <image_name> |
start | Allow to start one or more containers. | docker container start <container_id_or_name> |
stats | Allow to view the resource usage statistics of the running container. | docker container stats |
stop | Allow to stop one or more containers. | docker container stop <container_id_or_name> |
top | Allow to view the running process inside the container. | docker container top <container_id_or_name> |
unpause | Allow to unpause the processes of one or more container. | docker container unpause <container_id_or_name> |
update | Allow to update the configuration of one or more container. | docker container update –memory 100M –memory–swap 100M <container_id_or_name> |
wait | Allow to block until one or more containers stop, then print their exit code. | docker container wait <container_id_or_name> |
restart | Allow 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
You can subscribe to my YouTube channel for further reading.