Docker Tutorial

Docker Tutorial

What is container?

In DevOps, a container refers to a lightweight, isolated, and portable environment that encapsulates an application and its dependencies. Containers provide a consistent and reproducible way to package software, allowing it to run reliably across different computing environments.

What is docker ?

Docker is an open-source platform that enables developers to automate the deployment and management of applications within lightweight, isolated containers.

What is docker runtime ?

Docker runtime refers to the component of the Docker platform responsible for executing and managing containers. It is the underlying engine that enables the creation, deployment, and execution of containerized applications using Docker.

  1. runc - works with os, starts and stops the container

  2. containerd - managing runc and containers, image management, connecting with networks etc.

What is docker engine ?

Docker Engine, also known as Docker Daemon or Docker runtime, is the core component of the Docker platform. It is responsible for building, running, and managing Docker containers.

  1. Docker Daemon: The Docker Daemon (dockerd) is a background process that runs on the host machine. It listens for Docker API requests and manages container lifecycle operations, such as creating, starting, stopping, and deleting containers.

  2. Docker Client: The Docker Client (docker) is a command-line interface (CLI) tool that allows users to interact with the Docker Daemon. It provides a user-friendly way to issue commands and manage Docker containers, images, networks, and other resources.

  3. Docker Images: Docker Engine uses container images as the basis for creating and running containers.

  4. Networking and Storage: Docker Engine provides networking and storage capabilities for containers. It allows containers to communicate with each other and the external world through network interfaces.

  5. Docker Registry: Docker Engine integrates with Docker Registry, a centralized repository for storing and distributing container images.

What is orchestration ?

Docker orchestration provides the ability to manage a large number of containers and ensures that they run efficiently, reliably, and in a highly available manner. It enables the deployment of complex applications that consist of multiple interconnected containers, working together as a cohesive system.

Docker/Container Image -

Image in simple words can be said as the step by step instructions for an application whereas container is the running instance of the container. A Dockerfile is a text file that contains a set of instructions used to build a Docker image.

Open container initiative (OCI) -

Why it was created -

There were different container technologies with varying formats and runtimes, which made it challenging to switch between them or use them together seamlessly.

What does it do -

To establish open industry standards that promote interoperability among container technologies. By creating common specifications for container images and runtimes, the OCI aimed to ensure that containers and container runtimes could work together regardless of the specific implementation.

Docker CLI commands -

  1. docker run hello-world - looks for hello-world image locally, if not present then pull from online and created container of it, run here means it runs an image to create a container.

  2. docker images - give list of images downloaded on local machine

  3. docker images -q - gives list of id of all images

  4. docker pull ubuntu - only downloads the image and not run it.

  5. docker pull ubuntu:16/04 - downloads the ubuntu 16.04 version image

  6. ctrl+d - to exit out of container interactive shell enviroment

  7. docker run -it ubuntu - it flag states interactive enviroment here which doesn’t exit out of it’s own

  8. docker ps - to see all containers currently running

  9. docker ps -a - also shows all the containers that are stopped also

  10. docker container ls - list all the containers

  11. docker container exec -it <container-id> bash - connect the bash to the running container only specified by the id, doesn’t work if container is not running

  12. docker start <id> - starts the container with the id

  13. docker stop <container-id> - stops the running container with the help of it’s id

  14. docker rm <id> - removes the particular container

  15. docker inspect <id> or docker inspect ubuntu - gives all the information about the container

  16. docker container prune -f - removes all stopped containers

  17. docker run alpine ping [www.civo.com](civo.com)`` - run alpine image and then pings civo

  18. docker run -d alpine - docker detach(mode) container process and run it in the background

  19. docker run ubuntu echo hey - displays hey in terminal after running image

  20. docker logs —since 5s <id> - displays logs of particular container id in the past 5s

  21. docker rmi alpine -f - removes the alpine image forcefully but not the container

  22. docker run -d -p 8080:80 nginx - runs the container and makes it available to port using p flag and then specifying port number. -p takes to argument first the port on which we want to expose : then the default port of the nginx in the container which is by default 80.

  23. docker commit -m “new image making” <id> <image-name> - create your new image over the previous image-name now which we can share with others.

  24. docker rmi $(docker images -q) - it will remove all the images

What are layers ?

In Docker, images are made from layers. Every layer represents a change made to the previous layer, such as adding or modifying a file. Layers are immutable, meaning that once they are created, they cannot be changed. When a new image is created, it is built from the layers of the base image, with each additional layer representing changes specific to that image. This layering system allows Docker to efficiently share and store images, as well as quickly create new images based on existing ones.

Dockerhub ?

Similar to github we can download images and upload our images too.

  1. docker login - To login from command line into dockerhub

  2. Create you own dockerfile which then will be used for image

  3. Go to the directory where your application code is located.

  4. Create a new file called Dockerfile.

  5. Inside the Dockerfile, specify the base image you want to use.

  6. Add any necessary dependencies or libraries your application may need.

  7. Copy your application code into the Docker image.

  8. Set any necessary environment variables.

  9. Specify the command that should be executed when the Docker image is launched.

  10. Build the Docker image using the docker build command.

  11. docker build . - to make docker image by a file in current directory

  12. docker build -t myimage - to make docker image by the name myimage

  13. Run the Docker container using the docker run command.

What is gRPC?

gRPC is a high-performance, open-source framework developed by Google that allows developers to build distributed systems and microservices using a message-passing protocol. It is designed to be fast and efficient, with support for a wide range of languages and platforms. In Docker, gRPC can be used to create scalable and reliable microservices that can communicate with each other using a simple and efficient protocol.

In simple terms we can say that, Independent containers can definitely talk to each other using gRPC. Docker allows you to run multiple containers on the same machine or across different machines, and gRPC provides the communication mechanism between these containers.


Follow -

Comment below for suggestions and improvement :) Follow me for more such content 😀. If you have any doubts you can message me, and I will respond asap :)