mrityunjay saraf
Posted on June 23, 2023
π Table of content
πWhat is Docker
πAdvantage of Docker
πArchitecture of Docker
πWhat is Image
πWhat is Container
πDocker Commands
πImage Commands
πContainer Commands
π What is Docker
Docker is an open-source platform that enables the packaging, distribution, and deployment of applications using containerization.
Docker uses an isolated environment called container on the host OS to run applications. It allows applications to use the same Linux kernel as a system on the host computer, rather than creating a whole virtual OS.
Docker works only on the Linux kernel.
β¨ Advantage of Docker
πPortability: Containers are highly portable, allowing applications to run consistently across different environments.
πScalability: Docker enables efficient scaling of applications by quickly creating and deploying multiple containers.
πIsolation: Containers provide a level of isolation between applications, improving security and preventing conflicts between dependencies.
πEfficiency: Docker's lightweight architecture and shared OS resources result in efficient resource utilization and faster application startup times.
π Key concept of Docker
Containers,Images,Docker Registry is discussed soon in detail in different section of this blog.
Dockerfile: A Dockerfile is a text file that defines the instructions for building a Docker image.
Docker Engine: The Docker Engine is the runtime that enables the execution of Docker containers.
𧬠Architecture of Docker
- Docker client : provide the user an interface to communicate with the docker daemon in form of commands and REST API's req.
- Docker Host : It is the physical or virtual machine where the docker runtime environment is installed. It run the docker daemon (server) which listened to request from the docker client and manages the container and images.
-
Docker registry : A Docker registry is a central repository that stores Docker images.
- Public Registry: Access to everybody for ex : DockerHub
- Private Registry: registry accessed by any particular organisation.
π What is an Image
- A Docker image is a blueprint for creating containers. It contains all the necessary files, dependencies, configurations, and instructions for running a specific application or service.
- Each container created from an image is an instance of that image
- Docker images are stored in a registry, such as Docker Hub
π¦ What is the Container
πA Docker container is a lightweight and isolated runtime instance created from a Docker image.
πDocker containers encapsulate applications and their dependencies, providing a consistent and isolated runtime environment.
πDocker containers are highly portable and can run consistently on different systems, such as development machines, servers, cloud platforms.
πDocker containers can be easily scaled horizontally by running multiple instances of the same container.
π After the allocation of the host system resources to image container is created.
Image + Some part of your system resources (cpu,memory,storage) . = Container
Below example shows how container is made out of an image π
π Docker Commands
π Image Commands
-
docker image pull <image-name>:<tag>
:Pull an image from a registry
mrityunjay:~$ docker image pull redis:latest
latest: Pulling from library/redis
5b5fe70539cd: Pull complete
a1bc4b7ad0f0: Pull complete
a33d2f01ead9: Pull complete
94b33095e71c: Pull complete
d3c2b649b97c: Pull complete
8a5bf7f0acd7: Pull complete
Digest: sha256:6ccde0cb87c24c09b1970802b10e702ab4491ac932b79f69682609787379fa42
Status: Downloaded newer image for redis:latest
docker.io/library/redis:latest
-
docker image ls
: show all the images
mrityunjay:~$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest 8e69fcb59ff4 7 days ago 130MB
-
docker image inspect <image_name or image_id>
:Display detailed information on one or more images
mrityunjay:~$ docker image inspect redis
[
{
"Id": "sha256:8e69fcb59ff4a25f87cf68cf2558df9c56df3c3c8ef709677dc602a458fe9b2d",
"RepoTags": [
"redis:latest"
],
"RepoDigests": [
"redis@sha256:6ccde0cb87c24c09b1970802b10e702ab4491ac932b79f69682609787379fa42"
],
"Parent": "",
"Comment": "",
"Created": "2023-06-14T21:57:04.72797832Z",
"Container":
....
-
docker image rm <image_id / image_name>
: Delete one or more images
mrityunjay:~$ docker image rm redis
Untagged: redis:latest
Untagged: redis@sha256:6ccde0cb87c24c09b1970802b10e702ab4491ac932b79f69682609787379fa42
Deleted: sha256:8e69fcb59ff4a25f87cf68cf2558df9c56df3c3c8ef709677dc602a458fe9b2d
Deleted: sha256:fe526a32129d428c70598b5002c0c36375de4c593d5e9a9c5cb23b3029be6535
Deleted: sha256:5ae934b4bc8f1f63c0c096d7c33b9aa6782e4bf32c6584ab4a3374a5c2fea61b
Deleted: sha256:ad2888d341396ec43ce8c9526f4f706951cdd46b9c5c68248560fe19b7eeeebc
Deleted: sha256:ab6989ff03a00c9b4e5524e3858ba3ad6c939482d48434ad61c49bb5d390d31d
Deleted: sha256:67fa40895a637a6ffa36df77928cdd46f9f28f9ca2e7a5f5d1ca4851875b4956
Deleted: sha256:ac4d164fef90ff58466b67e23deb79a47b5abd30af9ebf1735b57da6e4af1323
-
docker image push <image-name>:<tag>
:Push an image or a repository to a registry -
docker image build .
: Build image from dockerfile
π NOTE : If you need any help related to docker image command just type
docker image command --help
mrityunjay:~$ docker image command --help
Usage: docker image COMMAND
Manage images
Commands:
build Build an image from a Dockerfile
history Show the history of an image
import Import the contents from a tarball to create a filesystem image
inspect Display detailed information on one or more images
load Load an image from a tar archive or STDIN
ls List images
prune Remove unused images
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rm Remove one or more images
save Save one or more images to a tar archive (streamed to STDOUT by default)
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
Run 'docker image COMMAND --help' for more information on a command.
π Container Commands
π― Creating the Container: This command will create the container of specific image in an interactive mode. But this will not run the container.
docker container create -it --name <container_name> <image_id / image_name>
- π― Starting the Container:
docker container start
will start the container.-i
will open container's console for i/o .CONTAINER
is either name or id of the container.
docker container start -i CONTAINER
- π― Running the Container :
docker run
command will create and run the container--name
will name the container and-it
allow you to interact with the container's console.-d
option make container run in deatched mode.
docker run -it --name <container_name> -d <image_name>
- π― Running the Command in Container:
docker exec
will execute the command in docker container.-it
will enable interactive mode.container
is either container name or idcommand
specify the command to be executed.
docker exec -it CONTAINER COMMAND
- π― Stopping the Container :
docker container stop
will stop the running containermycontainer
is either name or id of container.
docker container stop mycontainer
- π― Kill the Running Container :
docker container kill
command will forcefully terminate the container after try stopping conatiner gracefully usingdocker container stop
command.mycontainer
is either container name or container id.
docker container kill mycontainer
- π― Removing the container :
docker container rm
will remove the container.mycontainer
is one of more container_name or container_id.
docker container rm mycontainer
π NOTE : If you need help for the docker container command
docker container command --help
mrityunjay:~$ docker container command --help
Usage: docker container COMMAND
Manage containers
Commands:
attach Attach local standard input, output, and error streams to a running container
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
exec Run a command in a running container
export Export a container's filesystem as a tar archive
inspect Display detailed information on one or more containers
kill Kill one or more running containers
logs Fetch the logs of a container
ls List containers
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
prune Remove all stopped containers
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
run Run a command in a new container
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
wait Block until one or more containers stop, then print their exit codes
Run 'docker container COMMAND --help' for more information on a command.
π This is all about Images and Containers.In next blog will be be going to see how to Container the appication.
π¬ If you enjoyed reading this blog post and found it informative, please take a moment to share your thoughts by leaving a review and liking it π
Posted on June 23, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.