Unleash the power of Docker

Ankit Garg
Geek Culture
Published in
5 min readFeb 24, 2023

All you need to know to get handy with Containerization

Docker and Fun

“That works on my System” is a very usual thing we keep on hearing from fellow developers working on the same project. Well, we can’t deploy the machine so there should be a standard way to manage the environment across different machines.

A new deployment needs to be created in a new environment now you first set up all the basic software required to run the code The database, Redis, Nginx, and all other dependencies on the new machine, and remember the version should also match as per the requirement. Now you set up one of your friend's systems who has been using Linux, but your new friend also needs the code setup on his machine and he uses Windows so you have to run all the dependencies installations according to windows. No worries you did it well, then you updated one dependency on your system, and your co-workers on the same code base started getting errors.

Finally, you are tired of doing all this again and again, the solution to this problem is simply dockerizing your application code. For doing that you need to be well aware of all the objects that docker provides to containerize your application.

Docker objects

When you start using docker there are many different terms that you will keep on hearing images, containers, network, volume, plugins, and other objects. These objects are must-known things before you start using docker.

Images

Images are the initial template that is required to set up the docker container on your system. Images are made of other images, with some additional customization. An image defines which dependency needs to be installed with a specific version and commands to setup you your application code. An image can be created on your system and then published to the docker registry.

The instruction for creating a docker image is provided from Dockerfile .

An example of a Dockerfile to containerize a node application.

Containers

A container is a runnable instance of an image. You can use Dockerfile to create an image and this image can be used to run a container. There can be certain actions performed on a container like create, start, stop, move, or delete a container.

Some common Docker containers command:

== Run A Docker Image ==
$ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]

== Stop A Docker Image ==
$ docker stop [OPTIONS] CONTAINER [CONTAINER...]

== Listing Running containers ==
$ docker ps

== Kill A Docker Image ==
$ docker kill CONTAINER [CONTAINER...]

The Docker client

Docker client is a primary way to interact with docker APIs. Commands such as docker run those are sent to dockerd , which runs them. Docker client can communicate with more than one daemon.

The Docker daemon

Docker daemons manage the docker objects such as images, containers, networks, and volumes. It has the sole responsibility to listen for a docker API request to start, stop, and other actions done on containers and images.

Docker registries

A docker image once created need to be published on the network that can be downloaded and a container can be created using that image. Docker registry can be accessed by anyone to publish and download the images on their system. By default, docker looks on Docker Hub for any image.

By using docker pull or docker run commands, the required images are pulled from the configured registry. we will explore some of the most commonly used Docker commands for managing containers.

  1. docker run: The docker run command is used to create and start a new container. You can use this command to specify the container name, the image to use, the ports to expose, and any environment variables that the container needs.
  2. docker ps: The docker ps command is used to list all running containers. You can use this command to see information about the container, such as the container ID, the image name, and the status of the container.
  3. docker stop: The docker stop command is used to stop a running container. You can use this command to gracefully stop the container and allow it to clean up any resources it was using.
  4. docker rm: The docker rm command is used to remove a container. You can use this command to remove a container that is no longer needed or that is causing issues.
  5. docker logs: The docker logs command is used to view the logs of a container. You can use this command to see any output that the container generated, such as error messages or debugging information.
  6. docker inspect: The docker inspect command is used to view detailed information about a container. You can use this command to see information about the container’s configuration, networking, and storage.
  7. docker exec: The docker exec command is used to execute a command inside a running container. You can use this command to run debugging tools or to perform other operations inside the container.
  8. docker pull: The docker pull command is used to download an image from a registry. You can use this command to download a pre-built image or to update an existing image.
  9. docker build: The docker build command is used to build a new image from a Dockerfile. You can use this command to create a custom image that includes specific dependencies or configurations.
  10. docker-compose: The docker-compose command is used to manage multi-container Docker applications. You can use this command to define and manage the relationships between containers and to start and stop them together.

Docker provides a powerful platform for managing containers and deploying applications. By mastering these Docker commands, you can gain greater control over your containers and ensure that your applications run smoothly and efficiently.

--

--

Ankit Garg
Geek Culture

I write , So I learn @fullstackdev Go | JavaScript | Node js | React js