sudo apt-get install docker docker.io
# docker on start
sudo systemctl enable docker
# docker not on start
sudo systemctl disable docker
# docker without sudo
sudo groupadd docker
sudo usermod -aG docker <user>
# Log out and log in or use newgrp
newgrp docker
# Create container from image
docker create <image>
# Build image from the Dockerfile
docker build -t <image> <path>
# Create and start the docker
docker run --rm -it -p <port>:<EXPOSEport> -v <localpath>:<containerpath> <image>
# --rm remove container automatically after it exits
# -it connect container to terminal
# -p port
# -v volume share data between them, localpath is usually `pwd`
# --name <container>
# List docker configuration
docker info
# List running containers, use -a to include stopped images
docker ps
# Execute a command in the container
docker exec <container> <command>
# Start container
docker start <container>
# Attach a container
docker attach <container>
# Enter to an already running container
docker exec -it <container>
# Stop container through SIGTERM
docker stop <container>
# Stop container through SiGKILL
docker kill <container>
# Remove container, use -v to remove associated volumes
docker rm -f <container>
# List images
docker images
# Remove image
docker rmi -f <container>
# Remove stopped containers, networks not used, dangling images and dangling build cache
docker system prune
# Remove dangling images
docker image prune
# Remove dangling containers
docker container prune
# Check memory consuption
docker system df
# Save container in a zip
docker save <container> <ZIPname>.tar.gz
# List networks
docker network ps
# Host to container
docker network create --subnet <ip> <network>
# Assign IP to container
docker run -it --name <container> --ip <ip> --net <network> <image>
# Log in
docker login
# Download the image
docker pull <user>/<image>:<tag>
# Create a new image from a container’s changes
docker commit <container> <newimage>:<tag>
# Copy files/folders between container and the local file system
docker cp <localpath> <container>:<containerpath>
# Add tag to the image
docker tag <user>/<image>:<tag> <user>/<image>:<newtag>
# Upload the image
docker push <user>/<image>:<tag>
# List history of the image
docker history <user>/<image>:<tag>
# Display logs from the container
docker logs <container>
# Display EXPOSE port of the container
docker port <containter>
# List changes made to a container
docker diff <container>
# Show running processes in the container
docker top <container>