[Challenge Docker from 0] Overview and terms of Docker


I aim to get a job at an in-house developed company from inexperienced. I decided to study Docker to create a good portfolio.

Knowledge level is a level that can be easily developed using Ruby on rails, version control using git, and deployed using heroku. Also, I haven't done much linux or network-related study required to learn Docker. I hope it will be of some help to those who are thinking of trying Docker in the future at the same level as their own memorandum.

final goals

-It will be possible to build a Ruby on Rails environment from scratch using Docker. ・ To be able to migrate existing apps to the Docker environment

About Docker overview and terminology

What is Docker?

By definition, it is a "platform for creating, distributing, and running container-type virtual environments." To be honest, even if this explanation is given to beginners, it doesn't come to my mind.

** "Throwing an environment-built PC so that it can be used in various places" **

is. Perhaps anyone writing a simple application in Rails has encountered various errors. I think the most troublesome of these is environmental errors (personally). Also, in some cases, I think there was something like "It works well in the development environment, but it doesn't work in the production environment !!". As you can imagine, even though you are inexperienced, in the actual field, more libraries and tools are intricately intertwined, and you have to run the application in various environments such as production and development. Moreover, the same OS, device, server, etc. are not always prepared, and it is necessary to set the environment individually for each. Given these, it is easy to imagine that setting up the environment and taking over the environment is extremely difficult.

In such a case, it would be very easy if we could throw different environment settings and library dependencies for each PC so that they could be taken over in any environment. Docker has made this possible with virtual technology. Docker is said to be a container technology, but it is like putting the entire PC environment settings in a box called a container.

Benefits of Docker

There are four main benefits to using Docker. ・ There is no difference between environments ・ Since the environment is written in code, it is easy to understand even afterwards. ・ Easy to create an environment ・ Easy to abandon the environment ・ Light movement

I felt that the above merit was easy to understand if I understood the mechanism and usage of Docker's technology.

Operation and mechanism of Docker

Flow when using Docker

There are 4 steps when working with containers in Docker.

Explaining from ①, Dockerfile is simply a text that describes the environment settings and the actions you want to be performed in the environment. For example, describe what version of the tool to use. What is generated from that file is the Docker image of ②. A Docker image is simply like a blueprint. Then, create a container (entity) based on the image (design drawing) of ②. For those who have studied ruby, it may be easier to understand the relationship between class and instance for ② and ③. Then run the container and delete it when you no longer need it.

As mentioned above, Docker's strength is that you can easily create a Docker image (design drawing) by describing the environment settings as sentences in a Docker file (text file), as mentioned in the merit. If there is any change, you can change the description of Dockerfile and create / share the Docker image to achieve the same operation under any environment.

How Docker works

You may have understood the strength of Docker, but "Isn't it okay to create a virtual environment on a PC in all development environments using virtualBOX and then install the same OS on it? Some may think (maybe just me). But another strength of Docker is its lightness. In a normal virtual environment, it is necessary to build all the virtual OS and virtual CPU on the host OS. On the other hand, Docker is the same virtual technology, but it works by using the power of the kernel on the host OS, so there is no need to create a virtual environment from scratch. That's why Docker works very lightly.

Docker Glossary

Docker has various features and unique names. I would like to summarize the words that I will probably see in the future in my own words.

Docker container

It is a box that contains the OS and libraries. You can put environment settings in this and run various applications. For example, you can create a rails application on top of it by creating a box containing the macOS and rails libraries. You can pass the whole box when migrating to another environment, so you can easily migrate not only the rails code but also the underlying environment settings.

Docker image

It is a blueprint of the Docker container. A Docker container is created from the Docker image. It is the same as the relationship between a class and an instance of object-oriented programming. The Docker image is a class (no reality, something like a definition) and the Docker container is an instance (the place where it actually works).

Docker file This is a file for creating a Docker image. Write information here to define the image. Write this file and build (enter the build command) to create a Docker image. Because the environment settings are written in characters in this Dockerfile, Docker can easily edit the container and create an original image.

Docker hub A site with lots of Docker images. It's like the Docker version of Gitgub. You can create various Docker images on your PC and upload your own Docker images. The image posted on Dockerhub can be referenced by others, so you can easily share the original Docker image.

Docker machine An environment that allows you to create an environment for running Docker containers anywhere. With Docker maxhine, you can operate Docker containers on your local PC or in the cloud.

Docker compose For operating multiple containers. Since a container feels like one container and one function, it is necessary to prepare multiple containers for databases and web servers when managing applications with containers. Docker compose then makes it easy to manage multiple containers.

Docker Demon The heart of container technology. It is this Demon Kakka who starts and orders the container.

Summary / impression

If you were just a beginner in programming, it took you a while to understand what Docker was and what it was for. Moreover, since there are few introductory books, it seems a little difficult to get started. However, when I try to summarize it within myself, I feel that I have organized Docker.

[Articles from the next time onwards] [Challenge Docker from 0] Create a Ruby on Rails / MYSQL development environment using Docker and Docker-compose (part1) [[Challenge Docker from 0] Create a Ruby on Rails / MYSQL development environment using Docker and Docker-compose (part2)] (https://qiita.com/shu1124/items/5399ef69f940e5e19d59) [Challenge Docker from 0] Build a development environment for nginx / puma / rails6.0 / mysql using Docker

Helpful teaching materials / articles

"I've just started Docker, so I've summarized it in an easy-to-understand manner." https://qiita.com/gold-kou/items/44860fbda1a34a001fc1 → It covers very finely. I often see it as a referral.

"Docker course taught by US AI developers from scratch" https://www.udemy.com/course/aidocker/ → If you are a beginner learning Docker, this is it! !! !! Insanely easy to understand! !! !! It covers the environment construction with Docker from the basics of linux.

"Introduction to Practical Container Development for Docker / Kubernetes--Akinori Yamada" → Practical books, it may be a little difficult for beginners.

"Learn the basics in just one day! Docker / Kubernetes Super Introduction--Author" → If a beginner wants to learn from books, this is easy to get started.

Recommended Posts

[Challenge Docker from 0] Overview and terms of Docker
Overview of Docker and containers
Docker terms and commands
Challenge to install WSL2 and docker
End of Docker and Kubernetes: Grace period from SIGTERM to SIGKILL
[Challenge CircleCI from 0] Learn the basics of CircleCI
Introduction of Docker Hub and commands Self-learning ①
Learn more about docker image and Dockerfile FROM
Simple installation of nginx and Docker using ansible
A reminder of Docker and development environment construction
[Java] Overview of Java
Summary of frequently used commands in Rails and Docker
ArrayList and the role of the interface seen from List
Volume 3 types of Docker Compose considered from the purpose
Verification of the relationship between Docker images and containers
Introduction of Docker --Part 1--
CI/CD pipeline and Docker
Docker installation and initialization
[Terms] Static and dynamic
Overview of Spring AOP
Easy environment construction of MySQL and Redis with Docker and Alfred
[Summary of technical books] Summary of reading "Learn Docker from the basics"
Japanese localization of Docker container of CentOS7 / CentOS8 and Japan time setting