Docker Architecture
DevOps architecture consists of five main entities, namely, registry, image, container, daemon, and client.
Registry: It hosts public and official images. The Docker registry that we use is Docker Hub.
Image: It can be downloaded from the registry directly or implicitly when starting a container.
Container: It is basically the instance of an image. Multiple containers can exist for a single image.
Docker daemon: A daemon creates, runs, and monitors containers, along with building and storing images.
Client: A client talks to Docker daemon via HTTP.
Build
The build command is used for building images from a Docker file. Let’s now check out some of the essential Docker build commands.
Commands
- To build an image from the Docker file and tag it:
Docker build -t myapp :1.0
- To list all the images that are locally stored:
Docker images
- To delete an image from the Docker Store:
Docker rmi alpine: 3.4
Run
The run command is used for creating a container from a specified image. Check out the below-listed run commands.
Commands
- To create and run a command:
Docker run --name container_name docker_image
Flags used:
-d: To detach a container on start
-rm: To remove a container once it stops
-p: To publish the host IP and the host port to the container port
-v: To define and share the volume across containers
–read-only: To set to the read-only permission
Ship
Docker gives us the capability of shipping our application container anywhere, on any platform. Let’s check out some commands used for it.
Commands
- To pull an image from the registry:
Docker pull alpine:3.4
- To retag a local image with a new image name:
Docker tag alpine:3.4 myrepo/ myalpine:3.4
- To log in to the registry:
Docker login my.registry.com:8000
- To push an image to the registry:
Docker push myrepo/ myalpine:3.4
Clean up
To prevent wasting resources, we must know how to clean up. In this Docker cheat sheet tutorial, next, a few essential clean-up commands are provided.
Commands
- To clean an unused/dangling image:
Docker image prune
- To remove an image that is not used in a container:
Docker image prune -a
- To prune the entire system:
Docker system prune
- To leave a swarm:
Docker swarm leave
- To remove a swarm:
Docker stack rm stack_name
- To kill all running containers:
Docker kill $ (docker ps -q)
- To delete all stopped containers:
docker rm $(docker ps -a -q)
- To delete all images:
docker rmi $(docker images -q)
Services
Commands
To list all services running in a swarm:
Docker service ls
To see all running services:
Docker stack services stack_name
To see all service logs:
Docker service logs stack_name service_names
To scale a service across qualified nodes:
Docker service scale stack_name_service_name= replicas
Interact with container Commands
To run a command in a container:
Docker exe -ti container_name command.sh
To follow container logs:
Docker logs -ft container name
To save a running container as an image:
Docker commit -m “commit message” -a “author” container_name username/image_name: tag
Important Terms
Some of the important terms to know about while using Docker container are listed below:
Layer: Read-only files to provision the system
Image: Read-only layer that is the base of an image
Container: A runnable instance of the image
Registry/hub: A central place where images reside
Docker machine: A VM to run the Docker container
Docker Compose: A VM to run multiple containers as a system
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
Docker compose Commands:
docker-compose start
docker-compose stop
docker-compose pause
docker-compose unpause
docker-compose ps
docker-compose up
docker-compose down
Thank you for reading!! Hope you find this helpful.
#day20challenge#90daysofdevops
Always open for suggestions..!!
Thankyou Shubham Londhe !!