Table of contents
Hello readers, welcome to Docker Series Part-2.
Hope you all enjoy the previous article Docker Series Part-1 (Introduction to Docker)
if anyone of you missed, please check that article to get an idea about Docker.
In this article we are going to discuss about most commonly used docker commands.
Docker Commands
- To pull an image from a registry
# docker pull image_name
The above command pull latest version of the image from the docker hub registry
Docker Hub is a registry for docker images which contains many pre-build images that we can pull and try without needing to define and configure our own.
To pull specific version of the image we can use tag
- Example: To pull 'mysql' image with 8.0 version from the docker hub.
# docker pull mysql:8.0
- To list the docker images
# docker images
To upload a docker image into docker hub
# docker push image_name
To search for a docker image
# docker search image_name
To delete all images that are not attached to containers
# docker system prune -a
The above command will remove the following:
- all stopped containers
- all networks not used by at least one container
- all images without at least one container associated to them
- all build cache
To build an image from a customized container
# docker commit container_name/container_id new_image_name
To create an image from docker file
# docker build -t new_image_name
To delete a docker image from docker host
# docker rmi image_name/image_id
To see the list of all running containers
# docker container ls
To see the list of running and stopped containers
# docker ps -a
To start a container
# docker start container_name/container_id
To stop a running container
# docker stop container_name/container_id
To restart a running container
# docker restart container_name/container_id
To create a container from a docker image
# docker run image_name
To delete a stopped container
# docker rm container_name/container_id
To delete a running container
# docker rm -f container_name/container id
To see the logs generated by a container
# docker logs container_name/container_id
To see the ports used by a container
# docker port container_name/container_id