Understand the basics of docker

Summarize in this article

I studied based on this. At the very least, I'll summarize what you need to remember. Introduction to Docker/Kubernetes Practical Container Development

Basic matters to be held by the container

What is a container?

A logical partition (container) is created on the host OS, and the libraries and applications required to operate the application are put together so that they can be used as if they were individual servers.

Comparison with virtualized machines

● Understand that "the virtualized target is different" スクリーンショット 2020-11-30 13.33.12.png

The container management software (docker, etc.) virtualizes the "container", and the virtualization machine virtualizes the "OS". In an environment that uses containers, only the host OS is required, while in a virtual environment, a guest OS is required in addition to the host OS. Therefore, the container environment has less overhead than the virtual environment.

Overhead: CPU resource/disk capacity/memory usage required for virtualization Hypervisor: Software that specializes in virtualization on hardware (windows: Hyper-V, etc.)

● Different usage of system resources スクリーンショット 2020-11-30 13.48.20.png

In a virtual environment, multiple applications are usually run on the host OS (or guest OS), so it is necessary to manage the unification of middleware and library versions under the environment. On the other hand, in a container environment, applications can be easily made independent, so version control of the system environment is sufficient.

The power of continuous delivery

In application development, the waterfall of "development"-> "test"-> "staging"-> "production release" is basic, but it is necessary to unify the development environment in each process. Even if it works well in "development" and "test", it is impossible to release the service unless it matches the environment of the provider.

By using container management software, it is possible to easily realize "unification of the environment" by using a container image template, and it is possible to respond comfortably to changes in the environment. It has high continuous delivery power that can be deployed consistently from development to product release.

It is also very attractive that you can focus on development without having to spend time on library version control and resource construction.

Staging: Before the system is released, the system is reflected in an environment that is almost the same as the environment that actually provides the service (production environment), and the final confirmation of operation and display is performed. Or the environment.

Reference: https://codezine.jp/article/detail/11336

Docker

Basic functions of container management software "Docker"

Roughly speaking, docker users have the following three things to do independently.

Build: A function to create an image. Created from the infrastructure configuration information code (dockerfile). Ship: Ability to share images. Run: A function to move the container.

The following tools and engines are running as components that operate the above functions.

DockerEngine: Core function for creating images, starting containers, etc. DockerRegistry: Registry feature for publishing/sharing Docker images DockerCompose: A tool to centrally manage multiple container environments DockerMachine: A tool for automatically generating a docker execution environment with commands in a cloud environment DockerSwarm: A tool for clustering multiple Docker hosts

How Docker works

mojikyo45_640-2.gif

・ Virtual NIC is attached to the container -When docker is installed, the physical NIC of the host s aber and docker0 virtual bridge are connected. -Communication between containers on a single host is done via a virtual bridge -When the container is executed, a private IP address is automatically assigned to the container eth0. ・ When communicating with an external network, I use NAPT yesterday.

If you keep this image in mind, you can easily get an image of communication inside and outside the container.

Namespace: Technology for partitioning containers → Example: By limiting resources for each group, it is possible to prevent a specific container from running out of resources and affecting other containers.

Cgroups: Resource management → Divide into groups of parent-child relationships so that children cannot make settings that exceed the parental limit.

NIC: Network Interface Controller → Card-type expansion device for connecting devices such as computers to a communication network (LAN)

ethX: Ethernet port. Ethernet is a wired standard that supports the network interface layer of the TCP/IP protocol, which is a communication model between networks and computers.

Network bridge: A function that allows you to use one computer (a computer equipped with multiple wired LAN terminals and wireless LAN adapters) like a hub

Docker installation

See here. https://qiita.com/kurkuru/items/127fa99ef5b2f0288b81

To run the web server, refer to here etc. https://qiita.com/mtakehara21/items/d7be42cf12772f3ada25

Multiple container management

・ There is a tutorial below https://github.com/asashiho/dockertext2.git

docker-compose.yml


version: '3.3' #Specifying version
services: #List the services to configure
  # WebServer config
  webserver:
    build: . #Build "dockerfile" in the current directory

    ports:
     - "80:80"
    depends_on:
     - redis

  # Redis config
  redis:
    image: redis:4.0

From the following, configure the container according to docker-compose.yml

docker-compose up

スクリーンショット 2020-12-20 11.16.28.png

When accessing the port 80 version of localhost from a browser, the sample works as follows

スクリーンショット 2020-12-20 11.25.56.png

From the following, stop the container according to docker-compose.yml

docker-compose stop

YAML: Data format for representing structured data </​​font>

Multi-host environment and clustering

I have configured the docker environment on the host machine, but if a failure occurs on the host machine, the service will stop and availability and redundancy cannot be guaranteed.

For that, docker machine is used.

docker machine: A command line tool that allows you to create an execution environment such as docker in a host machine/cloud/virtual environment.

Availability: The degree and ability of a system to continue operating.

Redundancy: To prepare a spare system by duplicating the entire system including the network to improve fault tolerance.

スクリーンショット 2020-12-20 11.52.58.png

Kubernetes

Docker orchestration in cloud environment

The docker container can be installed manually when running on one machine such as in a development environment. However, in order to operate a production environment composed of multiple hosts in a cluster configuration, not only operations such as container start/stop, but also network connection between hosts, storage management, which host to run the container, etc. Scheduling function is essential. It is "kubernetes" that realizes this.

スクリーンショット 2020-12-20 12.11.33.png

Below is a list of servers that make up kubernetes

● Master server kubernetes A server for operating containers in a cluster. The master server receives the request by the kubectl command and executes the process. It is possible for the user to behave as if operating on one server.

● etcd server Distributed key-value store. Manage cluster configuration information. The setting information for configuring the cluster is written here.

● Node The server that actually runs the docker container. A cluster is a collection of multiple nodes. Inside the node, there is a pod, which is a collection of docker containers.

Below is a list of the elements that make up the application

●Replica Set Create/start a pre-specified pod with kubernetes. Monitor the pod, and if the container stops due to a failure, delete the pod and start a new pod.

●Deployment It manages the history of pods and ReplicaSets. When you want to upgrade the version of the container in the pod, you can update it without stopping the system.

スクリーンショット 2020-12-20 12.25.42.png

The following is a list of elements that manage the network

●Service Define Service when accessing the pod drafted in the kubernetes cluster from the outside.

●Label Use Label for resource management to make it easy to identify.

スクリーンショット 2020-12-20 12.54.13.png

Recommended Posts

Understand the basics of docker
Docker monitoring-explaining the basics of basics-
Understand the basics of Android Audio Record
The basics of Swift's TableView
[For beginners] Quickly understand the basics of Java 8 Lambda
Docker basics
Understand Docker
Understand the basic mechanism of log4j2.xml
About the basics of Android development
The basics of SpringBoot + MyBatis + MySQL
[Summary of technical books] Summary of reading "Learn Docker from the basics"
[Challenge CircleCI from 0] Learn the basics of CircleCI
Understand the official sample Coffee of Dagger2
The story of updating SonarQube's Docker Container
Now, I've summarized the basics of RecyclerView
Basics of Ruby
[day: 5] I summarized the basics of Java
Looking back on the basics of Java
I examined the concept of the process to understand how Docker works
What is JSP? ~ Let's know the basics of JSP !! ~
[Ruby] Summary of class definitions. Master the basics.
I understood the very basics of character input
Basics of jQuery that even freeters can understand
Improve the performance of your Docker development environment
The basics of the App Store "automatic renewal subscription"
Read the official Dagger2 documentation to understand the basics
[Docker Network Chapter 3] Understand the -net = host option
Change the location folder of Docker image & container
The world of clara-rules (2)
Judgment of the calendar
The world of clara-rules (4)
The world of clara-rules (1)
Let's understand the function!
The world of clara-rules (3)
Basics of try-with-resources statement
The world of clara-rules (5)
The idea of quicksort
The idea of jQuery
Volume 3 types of Docker Compose considered from the purpose
[For beginners] DI ~ The basics of DI and DI in Spring ~
I tried to summarize the state transition of docker
Docker the development environment of Ruby on Rails project
Understand the characteristics of Scala in 5 minutes (Introduction to Scala)
Verification of the relationship between Docker images and containers
I summarized the types and basics of Java exceptions
[WIP] I tried the configuration of Docker + Streama + NFS
SSL in the local environment of Docker / Rails / puma
[Ruby] Class nesting, inheritance, and the basics of self
Check the rate limit application status of docker pull
About the handling of Null
I didn't understand the behavior of Java Scanner and .nextLine ().
Docker Compose basics and commands
[GCD] Basics of DispatchQueue class
I tried to summarize the basics of kotlin and java
Now, I understand the coordinate transformation method of UIView (Swift)
About simple operation of Docker
Install by specifying the version of Django in the Docker environment
[Docker] Introduction of basic Docker Instruction
[Docker] List of errors that occurred when building the environment
The play of instantiating java.lang.Void
I've only heard of Docker ...