Here's a comprehensive cheat sheet of all the commands we have learned so far.
Command | Description |
Manage Images | |
docker images | Used to show the list of all the images |
docker pull <image-name> | Used to pull the docker image from docker repository(Docker Hub). Ex- docker pull mysql:latest |
docker push <image-name> | Used to push the docker image to the repository(Docker Hub). Ex- docker push my-image |
docker rmi <image-name> | Used to delete the image. Ex- docker rmi my-image |
docker image prune | Used to delete all the dangling images |
docker image prune -a | Used to delete all the unused images |
docker build directory | Used to build an image from a Dockerfile. Ex- docker build . |
docker build directory -t image-name | Used to build and tag an image from Dockerfile. Ex- docker build . -t nginx:latest |
Manage Containers | |
docker run <image-name:tagname> | Used to start a new container from the image. Ex- docker run mysql:latest |
docker run -d <image-name> | Used to start a new container from the image but detach it from the system and then run. Ex- docker run -d mysql:latest |
docker run --name container <image-name> | Used to start a new container from the image and assign a name to the container. Ex- docker run --name my_database mysql:latest |
docker run -p hostport:containerport image | Used to start a new container from the image and map a port. Ex- docker run -p 8000:8000 nginx |
docker ps | Used to show all the running containers |
docker ps -a | Used to show all the containers - running and stopped both |
docker rm container | Used to delete a container. Ex- docker rm container-id |
docker container prune | Used to delete all the stopped containers |
docker stop container | Used to stop the running container. Ex- docker stop container-id |
docker start container | Used to start the running container. Ex- docker start container-id |
docker exec -it container bash | Used to start a shell inside a running container.Ex-docker exec -it container-id bash |
docker rename <oldname><newname> | Used to rename a container with a new one. Ex- docker oldname newname |
docker kill container-id | Used to kill the running container. Ex- docker kill container-id |
Info & Stats | |
docker logs container | Used to show the logs of a container |
docker version | Used to show the version of installed docker |
docker inspect name | Used to show the detailed info about an object. |
Volumes | |
docker volume ls | Used to show the list of all volumes |
docker volume create --name <volume-name> | Used to create a volume and assign name to the volume |
Docker-compose | |
docker-compose up | Used to create and start multiple containers |
docker-compose up -d | Used to create and start multiple containers in detach mode |
docker-compose down | Used to kill and stop multiple containers |
Thanks!
Happy Learning!
~Shilpi