Docker Basics
docker pull <image>
: download a Docker image from a repositorydocker images
: list all Docker images on your systemdocker ps
: list all running Docker containersdocker ps -a
: list all Docker containers, including stopped onesdocker run <image>
: start a new Docker container from an imagedocker stop <container>
: stop a running Docker containerdocker rm <container>
: remove a stopped Docker containerdocker rmi <image>
: remove a Docker image from your system
Dockerfile
FROM
: specify the base image to use in a DockerfileRUN
: run a command during the build process of a Docker imageCMD
: specify the default command to run when a container is startedEXPOSE
: specify the port on which a container listensCOPY
: copy files or directories from the build context to the containerWORKDIR
: set the working directory for the containerENV
: set an environment variable for the container
Docker Images
docker images
: list all Docker images on your systemdocker image inspect <image>
: inspect the details of a Docker imagedocker image history <image>
: show the history of a Docker imagedocker image rm <image>
: remove a Docker image from your systemdocker image tag <source-image> <new-image-name>
: tag a Docker image with a new name and/or tag
Docker Compose
docker-compose up
: start the services defined in adocker-compose.yml
filedocker-compose down
: stop the services defined in adocker-compose.yml
filedocker-compose build
: build the Docker images defined in adocker-compose.yml
filedocker-compose ps
: list the running containers for services defined in adocker-compose.yml
file
Docker Volumes
docker volume create <name>
: create a new Docker volumedocker volume ls
: list all Docker volumes on your systemdocker volume inspect <name>
: inspect the details of a Docker volumedocker run -v <name>:<path>
: attach a Docker volume to a containerdocker run -v <host-path>:<container-path>
: mount a host directory as a Docker volume
Networking
docker network create <name>
: create a new Docker networkdocker network ls
: list all Docker networks on your systemdocker network inspect <name>
: inspect the details of a Docker networkdocker run --network <name>
: attach a container to a Docker networkdocker run -p <host-port>:<container-port>
: publish a container's port to the hostdocker run --expose <port>
: expose a port from the container to other linked containers
Docker Swarm
docker swarm init
: initialize a new Docker Swarm clusterdocker swarm join
: join a Docker Swarm clusterdocker node ls
: list all nodes in a Docker Swarm clusterdocker service create
: create a new Docker servicedocker service ls
: list all Docker services in a Swarm clusterdocker service ps <service>
: list the tasks for a Docker servicedocker service scale <service>=<num-replicas>
: scale a Docker service to a specified number of replicas
Docker Registry
docker login
: log in to a Docker registrydocker logout
: log out from a Docker registrydocker push <image>
: push a Docker image to a registrydocker pull <image>
: pull a Docker image from a registrydocker tag <source-image> <registry>/<repo>:<tag>
: tag a Docker image for a registry
Docker Logs
docker logs <container>
: display the logs of a running containerdocker logs -f <container>
: follow the logs of a running container in real timedocker logs --tail <number> <container>
: display the last n lines of a container's logs
Docker Exec
docker exec -it <container> <command>
: run a command inside a running containerdocker exec -it <container> sh
: open a shell session inside a running container
Docker Stats
docker stats
: display live resource usage statistics of all running containers
Docker Commit
docker commit <container> <image-name>
: create a new image from a running container's changes
Docker Build
docker build -t <image-name> .
: build a Docker image from a Dockerfile in the current directory and tag it with the given name
Docker Clean-up
docker system prune
: remove all stopped containers, unused networks, dangling images and cachesdocker container prune
: remove all stopped containersdocker image prune
: remove all unused imagesdocker volume prune
: remove all unused volumesdocker network prune
: remove all unused networks
Docker Security
docker run --privileged
: run a Docker container in privileged modedocker run --cap-add=<capability>
: add a Linux capability to a Docker containerdocker run --security-opt <security-option>
: add a security option to a Docker container
Docker System
docker system df
: display information about disk usage and container countsdocker system prune
: remove all unused containers, networks, images, and volumes
Thank you for reading!!
~Shreya Gupta
Great initiative by the #trainwithshubham community. Thank you Shubham Londhe
#devops #90daysofdevops #linux #docker #dockerproject