Neilblaze SVG FontNavigate back to the homepage

A brief Introduction to Docker

Pratyay Banerjee,Β 
January 1st, 2022 Β· 3 min read

What is Docker? πŸ‹

Docker is an open-source platform for deploying and managing containerized applications. It allows developers to easily package their applications into containers that can be deployed on every machine with a valid Docker installation.

docker

(1) ➀ Why use Docker? πŸ”

  • Write application once and deploy it everywhere
  • Docker allows for a rapid and seamless development and deployment process
  • Great CI and CD integration
  • Docker ensures your applications and services are isolated from each other and work all the time

docker-feat

(2) ➀ Docker Architecture

Dockers architecture is based on a client-server principle. The Docker client talks to the Docker Daemon, which is responsible for building, running, and managing the containers.

docker-arch

(3) ➀ Images

Images are read-only templates containing instructions for creating Docker containers. Images are often based on another image, the so-called base image, and add some additional customizations.

docker-img

(4) ➀ Image Registry

An image registry is a stateless, highly scalable central space for storing and distributing container images. They provide secure image management and a fast way to pull and push images with the right permissions.

(5) ➀ Container

A container is a runnable instance of a Docker image that can be managed using either the Docker CLI or API. You can connect your Containers to Networks, attach Storage, and even build images from their current state.

  • Containers are stateless by default, which means that the current state will be lost when the container is removed or restarts! πŸ’‘

(6) ➀ Volumes

Volumes are Docker’s preferred way of persisting data, which is generated and used by Docker containers. They are completely managed by Docker and can be used to share data between containers and the Host system.

volumes

(6) ➀ Networks

Networks are used to connect multiple Docker workloads with each other so they can communicate and share data. They can also be used to completely isolate single applications for maximum security.


Now, how to Install Docker? πŸ€”

On Windows and Mac, you can install Docker Engine, which will give you all the tools you need to use Docker out of the box. On Linux, I would recommend following the official installation guide provided by Docker.

But, how do you run a Docker (container)? πŸ€”

Containers are created using the docker run command, which takes the image name and version as a parameter.

run

You can also pass additional arguments using certain flags:

1-p, --publish: Publish container ports to the host system
2-v, --volume: Mount a volume to your container
3-e, --env: Add an environment variable to your container
4-i, --interactive: Attach to stdin
5-t, --tty: Pseudo tty

Let us look at an example to paint a clearer picture.

The name flag 🚩 is used to give the container a custom name, which helps when searching and filtering through multiple containers, and the -p flag exposes port 80 of the container to port 8080 of the host machine.

nginx

  • Listing all containers πŸ“‹ :-

Listing all containers can be done using the docker ps command, which returns all currently running containers.

list

If you want to list all containers instead, you can add the -a tag to the command.

list2

  • Stopping containers 🚫 :-

Stopping containers is also very simple and can be done using the docker stop command.

stop

The container id can be acquired by using the docker ps command. You can also stop all running containers using the following expression.

stop2

  • Removing containers πŸ—‘ :-

Removing containers is very similar to stopping them and can be done using the docker rm command.

remove

  • Executing commands in a container πŸ’»:-

Executing commands in already running containers is vital when using Docker and can be achieved using the docker exec command.

exec

For example, you can open a bash terminal in an already running container using the following command.

exec2

  • Get container logs πŸ“ˆ :-
1docker logs $CONTAINER_ID

Getting the logs of your container can be very important when debugging applications and searching for errors.

  • Get the resource usage of your containers πŸ”‹ :-
1docker stats

Sometimes it might be useful to check the resource usage of your containers to validate that your host machine is up to the job and that everything is workings as expected.


gif

Conclusion

That’s it for now! I hope you learned something valuable. There are many more tbh, I’ve only listed the most important ones. Go ahead and try them out.

That is all, I hope you liked the post. Thank you very much for reading, and have a great day! πŸ˜„

More articles from Pratyay Banerjee

10 Must know Commands in Linux

10 Linux command to get started into Linux based distros & rapidly increase productivity.

December 8th, 2021 Β· 3 min read

Deploying REST API's in Kubernetes

Beginner's guide on how to deploy REST API's on K8's aka Kubernetes

October 20th, 2021 Β· 3 min read
Β© 2021–2023 Pratyay Banerjee
Link to $https://twitter.com/NeilzblazeLink to $https://github.com/NeilblazeLink to $https://www.linkedin.com/in/x3nosizLink to $https://www.instagram.com/NeilzblazeLink to $https://facebook.com/NeilzblazeLink to $https://medium.com/@neilblaze