Docker Cheat sheet Series : Container
Part 1
docker container run centos echo “Welcome Pradeep”
Hey Docker, run the container called centos with the task or process called echo on the default network
docker container run — name <container_name> -d — network <network_name> centos ls -lrt
Run the container called container_name on the network called network_name
docker container run — name c5 -d — network <network_name_1> — network <network_name_2> centos ls -lrt
Run the container called container_name on the two networks called network_name_1 and network_name_2
docker container run — name <container_name> -P -d nginx:alpine
Run the container called container_name on port automatically selected by Docker.
Identify the port via (docker container port <container_name>)
docker container run — name <container_name> -p <host_port>:<container_port> -d nginx:alpine
Run the container called container_name on the host port called host_port which mapped to container_port called container port
docker container ls -h
Help on List container
docker container ls
List all currently-running containers
docker container ls -a
List all containers in any state, such as created, running, or exited
docker container ls -l
List the last run container
docker container ls -q
List the IDs of currently-running containers
docker container ls -aq / docker container ls -a -q
List the IDs all containers in any state, such as created, running, or exited
docker rm -f ${docker container ls -a -q}
Deletes all containers that are currently defined on the system of all the state
docker container stop <container_name>
Stop the container with name container_name
(Docker sends a Linux SIGTERM signal to the main process running inside the container.
If not, Docker waits for 10 seconds and then sends SIGKILL,
to kill the process forcefully and terminate the container)
docker container stop $<container_id>
Stop the container with name container_id
docker container start <container_name>
Start the container with name container_name
docker container rm <container_name> / <container_id>
Remove the container from memory
docker container inspect <container_name> / <container_id>
Inspect the container
docker container exec -i <task>
Run the additional process in the runn container
docker container attach <container_name> / <container_id>
Attach the current terminal to the mentioned quotes
docker container logs <container_name>
Retrieve the complete log from the beginning
docker container diff <container_name>
Retrieve the complete difference from the base image . A-Added,D-Deleted,C-Modified
docker container commit <container_name> <image_name>
Creating a new image called image_name from the current container called container_name
docker container logs — tail 10 <container_name>
Retrieve only the last ten items the process running inside the container
docker container logs — tail 10 — follow <container_name>
Retrieve only the last ten items the process running inside the container and follow it
docker container run — name <container_name> -it -v <volume_name>:<container_folder_name> centos /bin/sh
Mount the container container_name to volume volume_name of container_folder_name inside the container
docker container run — name <container_name> -it -v <volume_name>:<container_folder_name>:ro centos /bin/sh
Mount the container container_name to volume volume_name of container_folder_name inside the container in read only mode
docker container prune
Regain unused system resources by pruning containers