Docker is a tool designed to make it easier for developers to create, deploy, and run applications by using containers. Containers allows a developer to deploy an application as one package, which consists of all the required libraries, system tools, code and dependencies. Now, the developer can rest assured that the application will run on any other machine. The applications execution environment share operating system kernel but otherwise run in isolation from one another.
Consider containers as an extremely lightweight and modular virtual machines. You can easily create, deploy, copy, delete, and move these containers from environment to environment. They isolate applications execution environments from one another, but share the underlying OS kernel.
The Docker technology uses the Linux kernel and it’s features like Cgroups, which govern the isolation and usage of system resources, such as CPU and memory, for a group of processes and namespaces, which wrap a set of system resources and present them to a process to make it look like they are dedicated to that process; to segregate processes so they can run independently. This independence is the intention of containers—the ability to run multiple processes and apps separately from one another to make better use of your infrastructure while retaining the security you would have with separate systems.
Most business applications consist of several separate components: a web server, a database, an in-memory cache. Containers make it possible to compose these pieces into an individual functional unit. Each piece can be maintained, updated, swapped out, and modified independently of the others. This is essentially the microservices model of application design. By dividing application functionality into separate, self-contained services. Lightweight and portable containers make it easier to build and maintain microservices-based applications.
https://www.docker.com/products/docker-desktop
$ docker --version
Docker version 19.03.13, build 4484c46d9d
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:ca0eeb6fb05351dfc8759c20733c91def84cb8007aa89a5bf606bc8b315b9fc7
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
...
$ docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS
54f4984ed6a8 hello-world "/hello" 20 seconds ago Exited (0) 19 seconds ago
Dockerfile Commands
Node Dockerfile Example:
FROM node:12.18-alpine
ENV NODE_ENV=production
WORKDIR /usr/src/app
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]
RUN npm install --production --silent && mv node_modules ../
COPY . .
EXPOSE 80
CMD ["npm", "start"]
Docker image is a portable file containing the specifications for which software components the container will run and how. Once Dockerfile is written, invoke the Docker build utility to create an image based on that Dockerfile. Once an image is created, it’s static.
$ docker images
Docker run utility is the command that actually launches a container. Each container is an instance of an image. Containers are designed to be transient and temporary, but they can be stopped and restarted, which launches the container into the same state as when it was stopped. Further, multiple container instances of the same image can be run simultaneously.
$ docker run -p 80:80 -d node-test
docker run — starts container and runs any commands in that container there’s multiple options that go along with docker run including
These commands can be combined in ways too numerous to count, but here’s a couple simple examples of Docker commands.
$ docker build -t node-test .
This says to Docker: build (build) the image from the Dockerfile at the root level ( . ) and tag it -t as node-test. Don’t forget the period — this is how Docker knows where to look for the Dockerfile.
$ docker run -p 80:80 -d node-test
This tells Docker to run (run) the image that was built and tagged as node-test, expose port 80 on the host machine and look for port 80 inside the Docker container (-p 80:80), and start the process as a background daemon process (-d).
Docker also makes it easier to coordinate behaviors between containers, and thus build application stacks by connecting containers together.
Docker Compose was created by Docker to simplify the process of developing and testing multi-container applications. It’s a command-line tool, reminiscent of the Docker client, that takes in a specially formatted descriptor file to assemble applications out of multiple containers and run them in concert on a single host.
More advanced versions of these behaviors—what’s called container orchestration—are offered by other products, such as Docker Swarm
and Kubernetes
. But Docker provides the basics. Even though Swarm grew out of the Docker project, Kubernetes has become the de facto Docker orchestration platform of choice.
You can use Docker containers as a core building block creating modern applications and platforms. Docker makes it easy to build and run distributed microservices architectures, deploy your code with standardized continuous integration and delivery pipelines, build highly-scalable data processing systems, and create fully-managed platforms for your developers.
Docker simplifies and accelerates your workflow, while giving developers the freedom to innovate with their choice of tools, application stacks, and deployment environments for each project.
Refer well written docker documentation https://docs.docker.com/get-started/.
Refer Sample dockerfiles: https://github.com/sanmak/dockerfile-samples.