Docker Cheat Sheet
[vc_row][vc_column][vc_column_text]Image Build & Push
Command | What does it do? |
docker build -t myapp :1.0 . | To build an image from the Docker file and tag it |
docker image ls | To list all the images that are locally stored: |
docker rmi <name> | To delete an image from the Docker Store |
docker tag <name> <repo-url>/<name> | To tag an image with repo url or username and image name |
docker push <repo-url>/<name> | To push the docker image to repository |
Container Run & Manage
Command | What does it do? |
docker run <image-name> | To run a container from defined image
use -d to run container in background use -p to publish port to container use –name to name the container use -e to pass env variable in container use –restart to define restart behaviour |
docker ps | To list the running container use -a to see all container |
docker stop <container-id> | To stop a running container |
docker rm <container-id> | To remove a container in exited mode |
docker exec -it <container-id> <command> | To execute command inside container interactive shell |
docker inspect <container-id> | To list information of a container |
docker log <container-id> | To retrieve logs of application inside the container use -f to retrieve logs in streaming mode |
docker top <container-id> | To retrieve resource utilization of a container |
docker commit <container-name> | To create an image from a container |
Docker Volume
Command | What does it do? |
docker volume <name> | To create a docker volume |
docker run -v
Ex: docker run -v vol:/data redis docker run -v $PWD:/data redis |
Use -v flag followed volume name and mount path to mount a volume in container
OR Use -v flag followed host path and mount path to mount a volume in container |
docker volume inspect <volume-name> | To list information of a volume |
Docker Network
Command | What does it do? |
docker network create | To create new network use –type to define the driver type |
docker run –net
Ex: docker run –net mynetwork |
Use -v flag to run container in network of your choice |
docker network inspect <network-name> | To list information of a network |
Clean-up
Command | What does it do? |
docker system prune | To remove all containers, images, network and volumes |
docker stop $(docker ps -q -a) | To stop all running containers |
docker rm $(docker ps -q -a) | To remove all exited containers |
docker rmi $(docker image ls) | To remove all local images |
[/vc_column_text][thim-button title=”Download as PDF” url=”https://webmagicinformatica.com/wp-content/uploads/2022/04/Docker-Cheat-Sheet.pdf” new_window=”” custom_style=”custom_style” text_align=”text-center” border_width=”1″ hover_border_color=”#ffb606″ button_size=”medium” rounding=”tiny-rounded”][/vc_column][/vc_row]