This writeup is a dump of my study notes on most frequently used docker commands for reference. This is just a self reference page and will get updated on the go
- To run a container from an image
docker run <image name>
- To run a docker image with a specific tag. Example below of pulling redis image with tag4.0. You will get these tag details on the dockerhub page for the image
docker run redis:4.0
- To run a docker image in detached mode
docker run -d <image_name>
- To run a docker image and login to the container directly
docker run -it <image_name>
- To list all the docker images
docker images
- To pull a docker image from dockerhub but not run it.
docker pull <image_name>
- To list all the docker containers
docker ps -a
- To stop a docker container
docker stop <container_name>
- To remove a docker container form the disk.
Note: This will remove the container permanently. It will not list anymore indocker ps -a. However, the image still exists. The exited/stopped containers do not consume any CPU or memory, but they still use the machine’s disk space.
docker rm <container_name>
- To remove a docker image
docker rmi image
- To execute a command in a running docker container
docker exec <container_name> <command>
- To get the ip of a docker container
docker inspect <container_id/container_name> | grep IPAddress
- To map the internal port of a docker container to a host port
docker run -p 80:5000 <image_name>
- To get the logs of a container
docker logs <container_name>
- To build a docker file
docker build . #from being in the dir which has Dockerfile
- To map an external directory at the bootup to a docker container
docker run -v /myCustomdir:/defaultDir -u root imageName
Very efficient. Thanks a lot.
LikeLike