DEV Community

Cover image for Getting Started with Docker
Niti Kaur
Niti Kaur

Posted on

Getting Started with Docker

What is Docker?

Docker is a sophisticated platform that enables IT teams to effortlessly design, test, and deploy programmes in Docker containers, complete with all of its dependencies. In a Dockerfile, a developer defines all of the programmes and their dependencies, which are then used to create Docker images, which define a Docker container. Docker can be utilised at several points of the DevOps cycle, but it excels in the deployment stage. It is more powerful than Virtual Machines and has additional features that developers would appreciate.

Advantages of using Docker

Docker can speed up the delivery of your code and provide you more control over your applications. You can run programmes in containers, which makes it easier to deploy, scale, rollback, and troubleshoot difficulties. It also aids in cost-cutting by maximising resources. Docker-based applications may be transferred from local development to production deployments with ease. Microservices, Data Processing, Continuous Integration and Delivery, and Containers as a Service are all possible with Docker.

How does Docker work?

Docker creates, manages, and operates containers. The operating system provides access to container technology: A container contains all of the libraries, configuration files, dependencies, and other components and parameters required for the application service or function to work. One underlying operating system is shared by all containers. Containers that travel between Docker environments with the same OS run without changes since Docker images contain all of the dependencies needed to execute code within a container.

To run several containers on the same OS, Docker leverages resource isolation in the OS kernel. Virtual machines (VMs), on the other hand, enclose a whole operating system with executable code on top of an abstraction layer of physical hardware resources.

Image description

Docker Architecture

Docker is built on a client-server model. The Docker client communicates with the Docker daemon, which handles the construction, execution, and distribution of your Docker containers.

Image description

Docker Daeomon

It handles Docker objects such as images, containers, networks, and volumes by listening to API calls made through the Docker client.

Docker Client

This is how you communicate with Docker. When you use docker to perform a command, the client delivers the command to the daemon, which executes it. The Docker client has the ability to communicate with many daemons.

Docker Registries

This is where Docker images are stored. Docker Hub is a public registry that anyone can use. When you pull an image, Docker by default looks for it in the public registry and saves the image on your local system on DOCKER_HOST. You can also store images on your local machine or push them to the public registry.

Dockerfile

This article explains how to make a Docker image. It's similar to a recipe, with all of the ingredients and processes you'll need to make your cuisine. You can use this file to make a Docker image. In any setting, these images can be used to construct containers. These images can also be saved to docker hubs online. Docker containers are created when you run docker image. The programme will be in the container, along with all of its dependencies.

Containers

A container is an image that can be run. This is the location where your application runs. The Docker API or CLI can be used to manage containers. You can attach storage to a container, connect it to one or more networks, or even construct a new image based on its existing state. Data will be lost if we delete a container! Because the last layer was produced as a new layer when the container fell down and then brought back up. If you don't want to keep a record for each test, this is useful in development. Use volumes to store data if you want to be persistent.

Some Basic Commands

  • docker --version - tells us the current version of docker

Image description

  • docker pull - pulls images from docker repository
docker pull <image name>
Enter fullscreen mode Exit fullscreen mode

Image description

  • docker run - creates a container from an image
docker run <image name>
Enter fullscreen mode Exit fullscreen mode

Image description

  • docker ps - lists the running containers

Image description

  • docker ps -a - shows all running and exited containers

Image description

  • docker exec - accesses the running container

docker exec -it bash_

Image description

  1. docker stop - stops a running container
docker stop <container id>_
Enter fullscreen mode Exit fullscreen mode

Image description

  1. docker kill - kills the container by stopping the execution completely
_docker kill <container id>_
Enter fullscreen mode Exit fullscreen mode

Image description

  • docker commit - creates a new image of an edited container on the local system
docker commit <container id> <username/imagename>
Enter fullscreen mode Exit fullscreen mode

Image description

  • docker login - used when in logging into the docker hub repository

Image description

  • docker push
docker push <username/image name>
Enter fullscreen mode Exit fullscreen mode

Image description

  • docker images - lists all locally stored docker images

Image description

1- docker rm - deletes a stopped container

docker rm <container id>
Enter fullscreen mode Exit fullscreen mode

Image description

  • docker rmi - deletes image from local storage
docker rmi <image-id>
Enter fullscreen mode Exit fullscreen mode

Image description

Top comments (0)