Docker has gained popularity among DevOps teams recently due to its efficient and straightforward usage of containerization technology. Let us take a brief look at Docker in this post. There will be few additional posts in continuation of this, where we will discuss few additional details.
What is Docker ?
- Docker is a tool that automates the deployment of applications inside software containers. It is promoted by the company Docker, Inc.
- A Docker Container is an open source software development platform. Its main benefit is to package applications in “containers,” allowing them to be portable from one computing environment to another. This helps in software development process which requires several iterations of testing and development across different environments – from the PC of a developer to QA test environment – from staging to production environments.
- A Container holds an application and everything needed to run it, such as dependencies, libraries, other binaries and configuration files – all of which bundled together in a single package. Anyone can run the containerised application image from their system without worrying about the underlying requirements.
- Although it is easy to create and destroy containers at will, it has new challenges. In a production environment, there might be thousands of containers running various application components. This brings in the requirement for container orchestration tools, which can manage the resources, virtual machines and containers.
Why Docker Containers ?
- Docker containers use less RAM and start instantly.
- Efficient use of disk space and image downloads because images are constructed from layered file systems and share common files.
- As Docker is lightweight and portable, it is easy to dynamically manage workloads, scale up or tear down applications depending upon business requirements.
- Docker uses client-server architecture. The docker engine consists of three major components.
- A server which is a type of long-running program called a daemon process (dockerd). The daemon creates and manages Docker objects, such as images, containers, networks, and volumes.
- The Docker client communicates with the Docker daemon using REST API over unix sockets or a network interface. There is also a command line interface based Docker client, which can be used to connect to the daemon. The Docker client and daemon can run on the same system, or you can connect a Docker client to a remote Docker daemon.
- A Docker image is a read only template which has instructons for creating a container. A Docker container is a runnable instance of a Docker image. A Docker registry is a library of images.
- A Docker image is often based on another image, with some additional customization.
- You might create your own images or you might only use those created by others and published in a registry.
- To build your own image, you create a Dockerfile with a simple syntax for defining the steps needed to create the image and run it. Each instruction in a Dockerfile creates a layer in the image. When you change the Dockerfile and rebuild the image, only those layers which have changed are rebuilt. This is part of what makes images so lightweight, small, and fast, when compared to other virtualization technologies.
- The base image is defined using the FROM keyword in the Dockerfile.
- Docker registries are the distribution components and can be private or public. Registries can be on the same server as the daemon process or on a remote server.
- Registries store Docker images. After images are built, they can be pushed to a public or private registry.
- Docker Hub – is a public Docker registry and has a huge collection of images. Others can contribute Docker images of their own to Docker Hub.
- Docker Store – allows anyone to buy and sell Docker images.
- Docker containers are the run components of Docker.
- Using CLI or Docker API, anyone can run, stop, start, move or delete a container.
- Each container is built from an image and behaves like an isolated and secure application platform. They also can access resources running on different hosts and containers.
- The CLI command “docker run” is used for instructing the daemon to run the container. This can also be accomplished by an equivalent API.
- Installing Docker on Windows can be very easy
- Download the required installation image
- Then Double click the downloaded file to install it.
- The installation completes
- While launching Docker, you may be asked whether to enable Hyper-V. Be aware that clicking the OK option will restart the computer. Also note that if you have already installed Virtual Box, that will no longer work.
Launching Docker CLI
- After Windows restarts, launch the command prompt or powershell and enter the following command to verify the version of Docker:
- Run the command “docker ps” to make sure it works
- Run the following command to test pulling an image from Docker Hub and starting the container
docker run hello-world
- Docker services are the scalability component of Docker.
- They enable a swarm of Docker nodes to work together.
- Docker services allow a defined number of instances of replica tasks. These replica tasks themselves are Docker images. You can specify a number of concurrent replica tasks to run.
- The swarm manager evenly distributes the load across worker nodes, so it appears as a single application to the consumer.
- The docker service command is used for creating, updating inspecting, listing and scaling the services.
- To create a new service use the command format given below :
docker service create –name [name] image
Example : docker service create –name redis redis:3.0.6
Docker Run Example
- Try to run an Ubuntu container using “docker run ..”
- This will download the ubuntu container image and start it. Here is the output of running this command in a powershell.