## Docker Cheat Sheet ### Docker Data Directory - **State Less:** Don't save your data like Nginx. - **State Full:** Save your data. - `/var/lib/docker/` ==> Docker data directory ### Docker Commands #### Login to Docker Hub ```bash docker login ``` #### Pull Docker Image ```bash docker pull ``` #### Show Pulled Images ```bash docker images ``` #### Run Docker Container ```bash docker run ``` - **Options**: - `-it`: Run interactively and allocate a pseudo-TTY. - `-dit`: Run in detached mode with interactive TTY. #### Go to Container Shell ```bash docker exec -it bash ``` #### Remove Docker Container ```bash docker rm ``` #### Stop Docker Container ```bash docker stop ``` #### Stop and Remove Docker Container ```bash docker rm -f ``` #### List Docker Containers ```bash docker ps -aq ``` #### List Exited Docker Containers ```bash docker ps -aq -f status=exited ``` #### Remove Exited Docker Containers ```bash docker rm $(docker ps -aq -f status=exited) ``` #### Remove All Stopped Containers ```bash docker container prune ``` #### Container Configuration and Files - `/var/lib/docker/containers/` ==> Container config and file directory #### Get Container Information ```bash docker inspect ``` #### Get Container IP Address ```bash docker inspect --format '{{ .NetworkSettings.IPAddress }}' ``` #### Copy Files Between Local and Container ```bash docker cp :/ docker cp :/ ``` #### Monitor Docker Container Statistics ```bash docker stats ``` #### Run Container with Restart Policy ```bash docker run -dit --name server --restart=always ubuntu ``` #### Create Custom Docker Image ```bash docker commit ``` #### Save Docker Image to External File ```bash docker save -o ``` #### Remove Docker Image ```bash docker rmi -f ``` #### Load Docker Image from File ```bash docker load -i ```