Overview of Docker and containers

Regarding this article

Created for in-house young study sessions It explains as easily as possible, understanding the outline, building the environment, and actually operating it.

environment

Overview of Docker and containers

What is a container?

One of the virtualization technologies

What is Docker

One of the container engines shown below

Difference between conventional virtualization (hypervisor type) and container

The story of the OS and the OS kernel

Docker for Windows environment construction

Enable Hyper-V

Since it is necessary to enable Hyper-V to run Docker on Windows, Execute the following command with powershell opened with administrator privileges, Enable Hyper-V (PC restart required)

>Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All

After restarting, check if Hyper-V is enabled in BCDEdit * Execute the following command with powershell, If it is output by hypervisorlaunchtype Auto, it has been successfully enabled.

bcdedit /enum | find '"hypervisorlaunchtype"'

If it is off, execute the following command and restart again.

bcdedit /set hypervisorlaunchtype auto

Installation & setup of docker for windows

Get Docker for Windows (2.3.0.4 stable edition) from the link below https://docs.docker.com/get-docker/

Reboot after installation After restarting, start Docker and the Docker startup procedure will be displayed After the installation is complete, docker for windows will be added to the indicator at the bottom right of the screen

Because it requires a lot of memory to start an image or container Change the memory allocation from 2GB to 4GB from [Setting] → [Resources]

The following is only for those who need proxy authentication

Enter the following settings in [Setting] → [Resources] → [PROXIES]. -Http: // : @ proxy host name: proxy port number/set

Why you need Hyper-V (hypervisor) even though it is a container

Hyper-V is a hypervisor, isn't it necessary for containers? You might think This is because the Docker container is based on Linux and requires a Linux kernel. Docker for Windows builds a Linux OS with Hyper-V on Windows OS, The Linux kernel on that Hyper-V is shared by the container

image2021-1-6_19-33-42.png

Once you have prepared the operating environment for Docker, you can run your favorite container. Containers can be obtained from a management location on the Internet called Docker Hub (* described later) At this time, the container is distributed in a snapshot-like format called a container image. After acquiring the image, it can be operated as a container by executing it.

Docker operation

DockerHub Container images can be obtained mainly from a management location on the net called Docker Hub Only image search is possible without user registration Here you can check the image name, provider, latest version, etc. https://hub.docker.com/

Get Docker image-Run container

Once you get docker for Windows, you can run docker commands from the command prompt Actually get a lightweight linux image called alpine from docker hub and run it


>docker pull alpine:latest
latest: Pulling from library/alpine
801bfaa63ef2: Pull complete                                                                                                                                                                                                                  Digest: sha256:3c7497bf0c7af93428242d6176e8f7905f2201d8fc5861f45be7a346b5f23436
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest
 
>docker images
REPOSITORY                           TAG                    IMAGE ID            CREATED             SIZE
alpine                               latest                 389fef711851        2 weeks ago         5.58MB
 
>docker run -it  -d  alpine:latest  /bin/sh
 
>docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
c3a9d3cc09f4        alpine:latest       "/bin/sh"                6 seconds ago       Up 3 seconds                                 loving_mendeleev
 
docker exec -it c3a9d3cc09f4 /bin/sh
/ # ls
bin    dev    etc    home   lib    media  mnt    opt    proc   root   run    sbin   srv    sys    tmp    usr    var
/ # exit

The explanation of each command is as follows

image2021-1-7_10-47-17.png

Dockerfile

When actually creating a container, in addition to the base image Often create a container with the necessary middleware and apps It is possible to operate inside the started container, When you create a configuration as a Dockerfile, You will be able to set up and copy resources automatically

Launching a web server container using Dockerfile

Here is an example of creating a simple web server container

Dockerfile


#Use image of web server nginx
#Pull the image specified here from docker hub
FROM nginx:alpine
#You can copy materials from a local terminal to a container environment with ADD
#/usr/share/nginx/html is the place to store html to be displayed by nginx
ADD ./index.html /usr/share/nginx/html
#Free up 80 ports in the container
EXPOSE 80
#Set the entry point for the container
ENTRYPOINT /usr/sbin/nginx -g "daemon off;" -c /etc/nginx/nginx.conf

index.html


hello world,Docker

After creating the above file, execute the following command in the saved directory

Working folder/◀ Start command prompt here ├ Dockerfile └index.html

>docker build -t myimage .
Sending build context to Docker daemon  4.096kB
Step 1/5 : FROM nginx:alpine
 ---> 629df02b47c8
Step 2/5 : CMD echo "now running..."
 ---> Using cache
 ---> 2b4f225ff66e
Step 3/5 : ADD ./index.html /usr/share/nginx/html
 ---> Using cache
 ---> 8de80809c52c
Step 4/5 : EXPOSE 80
 ---> Using cache
 ---> 90168e587d3b
Step 5/5 : ENTRYPOINT /usr/sbin/nginx -g "daemon off;" -c /etc/nginx/nginx.conf
 ---> Running in eb60ad7be198
Removing intermediate container eb60ad7be198
 ---> d4d131ab1d24
Successfully built d4d131ab1d24
Successfully tagged myimage:latest
 
>docker run --name mycontainer -d -p 30080:80 myimage

image2021-1-7_14-34-30.png image2021-1-7_14-42-59.png

Impressions of actually using the container

Because the project I currently belong to uses various technologies It was difficult to build the environment one by one, but when using Docker, If you generate a Dockerfile and put it in the source repository I find it very useful because each member can create a container environment and move their hands. Actually, I use a technology called docker-compose that can set up multiple containers. I'm exhausted so please refer to another article Also, when it comes to actual operation, it is essential to use orchestration tools such as k8s. I thought that this level of knowledge was sufficient for light movements such as feasibility studies.

Recommended Posts

Overview of Docker and containers
[Challenge Docker from 0] Overview and terms of Docker
Verification of the relationship between Docker images and containers
Introduction of Docker Hub and commands Self-learning ①
[Java] Overview of Java
Simple installation of nginx and Docker using ansible
A reminder of Docker and development environment construction
Introduction of Docker --Part 1--
CI/CD pipeline and Docker
Docker installation and initialization
Docker terms and commands
Overview of Spring AOP
Summary of frequently used commands in Rails and Docker
Docker settings and this and that
Setup of JMeter and jEnv
Background and mechanism of Fabric-loader
Docker monitoring-explaining the basics of basics-
Summary of FileInputStream and BufferedInputStream
Docker Compose basics and commands
About simple operation of Docker
Latest docker installation (Ubuntu 20.04 and Ubuntu 20.10)
[Docker] Introduction of basic Docker Instruction
Understand the basics of docker
I've only heard of Docker ...
Easy environment construction of MySQL and Redis with Docker and Alfred
Combination of search and each_with_index
Judgment of JSONArray and JSONObject
Comparison of Web App for Containers and Azure Container Instances
Operator of remainder and exponentiation (exponentiation)
Advantages and disadvantages of Java
JavaScript overview and basic grammar
Japanese localization of Docker container of CentOS7 / CentOS8 and Japan time setting
Installing and building Docker (memo)
End of Docker and Kubernetes: Grace period from SIGTERM to SIGKILL
Basics of conditional branching and return
Docker all containers, images (stopped, deleted)
About fastqc of Biocontainers and Java
[Docker Network Chapter 2] Explanation of Docker Networking
[Docker Network Chapter 1] Explanation of Docker Networking
Hello World with Docker and C
Proper use of redirect_to and render
This and that of the JDK
Summary of frequently used Docker commands
[Swift] Advantages and disadvantages of Storyboard
Proper use of Mockito and PowerMock
[Java] Judgment of identity and equivalence
[Rails] Differences and usage of each_with_index and each.with_index
About removeAll and retainAll of ArrayList
This and that of Core Graphics
2. Create Docker image and register Registry
Default implementation of Object.equals () and Object.hashCode ()
Application of downcase and slice methods
Microservices With Docker and Cloud Performance
Docker [Batch deletion of <none> tags]
Challenge to install WSL2 and docker
This and that of exclusive control
About Docker, disguise server and container
Make a daily build of the TOPPERS kernel with Gitlab and Docker
Installing Docker Desktop on Windows 10 Home was easy and easy (as of December 2020)