What is Docker?
Docker is a tool that enables you to create, deploy, and manage lightweight, stand-alone packages that contain everything needed to run an application (code, libraries, runtime, system settings, and dependencies). These packages are called containers.
Each container is deployed with its own CPU, memory, block I/O, and network resources, all without having to depend upon an individual kernel and operating system. While it may be easiest to compare Docker and virtual machines, they differ in the way they share or dedicate resources.
Containers help expand your Server functionality in a number of ways. For example, you can deploy multiple instances of
nginx with multiple stagings (such as development and production). Unlike deploying multiple virtual machines, the deployed containers will not increase resource usage.
Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.
Each Docker container is created from an image. You pull images from a Docker registry - such as the official Docker Hub - and use them to build containers. A single image can create numerous containers. For example, you could use the latest
nginx image to deploy a webserver container for:
- Web dev ops
- Web applications
Dockerfile is a text file that contains the necessary commands to assemble an image. Once a
Dockerfile is written, the administrator uses the
docker build command to create an image based on the commands within the file. The commands and information within the
Dockerfile can be configured to use specific software versions and dependencies to ensure consistent and stable deployments.
Dockerfile uses the following commands for building the images:
- ADD - copy files from a source on the host to the container's own filesystem at the set destination.
- CMD - execute a specific command within the container.
- ENTRYPOINT - set a default application to be used every time a container is created with the image.
- ENV - set environment variables.
- EXPOSE - expose a specific port to enable networking between the container and the outside world.
- FROM - define the base image used to start the build process.
- MAINTAINER - define the full name and email address of the image creator.
- RUN - central executing directive for
- USER - set the UID (the username) that will run the container.
- VOLUME - enable access from the container to a directory on the host machine.
- WORKDIR - set the path where the command, defined with CMD, is to be executed.
Not every command must be used. Below is a working
Dockerfile example, using only the
MAINTAINER NAME EMAIL FROM debian:latest RUN apt-get -y update && apt-get -y upgrade && apt-get install -y build-essential
Docker makes it easy to join servers together to form a cluster, called a Docker Swarm. Once you’ve created a Swarm manager, or leader, and attached nodes to the leader, you can scale out container deployment. The leader will automatically adapt the cluster by adding or removing tasks to maintain a desired state.
A node is a single instance of the Docker engine that participates in the Swarm. You can run one or more nodes on a single instance. The Swarm manager uses ingress load balancing to expose services that can be made available to the Swarm. Docker Swarm can also:
- Check the health of your containers.
- Launch a fixed set of containers from a single Docker image.
- Scale the number of containers up or down (depending upon the current load).
- Perform rolling updates across containers.
- Provide redundancy and failover.
- Add or subtract container iterations as demands change.
In this article, you learned the basics of working with Docker, various concepts and how to get started with Docker configuration.
See you soon!!