Files
my-docs/Docker/Docker.md
2024-05-10 18:11:04 +03:30

2.1 KiB

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

docker login

Pull Docker Image

docker pull <repo-addr>

Show Pulled Images

docker images

Run Docker Container

docker run <options> <image>
  • Options:
    • -it: Run interactively and allocate a pseudo-TTY.
    • -dit: Run in detached mode with interactive TTY.

Go to Container Shell

docker exec -it <container name> bash

Remove Docker Container

docker rm <container name or ID>

Stop Docker Container

docker stop <container name or ID>

Stop and Remove Docker Container

docker rm -f <container name or ID>

List Docker Containers

docker ps -aq

List Exited Docker Containers

docker ps -aq -f status=exited

Remove Exited Docker Containers

docker rm $(docker ps -aq -f status=exited)

Remove All Stopped Containers

docker container prune

Container Configuration and Files

  • /var/lib/docker/containers/ ==> Container config and file directory

Get Container Information

docker inspect <container name or ID>

Get Container IP Address

docker inspect --format '{{ .NetworkSettings.IPAddress }}' <container name>

Copy Files Between Local and Container

docker cp <file_on_local> <container-name>:/<location>
docker cp <container-name>:/<location> <local_location>

Monitor Docker Container Statistics

docker stats

Run Container with Restart Policy

docker run -dit --name server --restart=always ubuntu

Create Custom Docker Image

docker commit <containername> <newname>

Save Docker Image to External File

docker save -o <file-location-and-name> <image-name>

Remove Docker Image

docker rmi -f <image-id>

Load Docker Image from File

docker load -i <file-location>