Docker I use it for business, but I don't think I understand the mechanism so deeply, so Let's start with the basics.
Contrast with virtualization
|Virtualization||OS||Uses a unique kernel for each VM||It emulates HW using a hypervisor and runs multiple OSs, so processing is heavy.|
|container||process||Share host OS kernel||The process is light because it is a process rather than running the OS|
Specifically, processes are isolated using kernel functions such as Namespace and cgroup. (Details in the future)
In other words, because it is light, you can easily deploy apps.
The platform that runs the container. You can build and run applications in containers, or distribute containers (Docker images, Dockerfiles).
--CentOS7 on Vagrant
#Remove if you have an older version of Docker installed [[email protected] ~]$ sudo yum remove docker* #Add docker repository [[email protected] ~]$ sudo yum install -y yum-utils [[email protected] ~]$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo # docker-ce-Make sure the stable repository is enabled [[email protected] ~]$ cat /etc/yum.repos.d/docker-ce.repo #Package update [[email protected] ~]$ sudo yum -y update #Latest installation of Docker Engine and containerd [[email protected] ~]$ sudo yum -y install docker-ce docker-ce-cli containerd.io #Version confirmation [[email protected] ~]$ docker -v Docker version 20.10.1, build 831ebea #Start Docker [[email protected] ~]$ sudo systemctl start docker # hello-Download and run world Image [[email protected] ~]$ sudo docker run hello-world ~ Omitted ~ #Success if this is displayed Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
#Make sure the docker group is created when you install docker [[email protected] ~]$ cat /etc/group | grep docker docker:x:993: #Add current user to docker group [[email protected] ~]$ echo $USER vagrant [[email protected] ~]$ sudo usermod -aG docker $USER #Reflection of changes [[email protected] ~]$ newgrp docker [[email protected] ~]$ id uid=1000(vagrant) gid=993(docker) groups=993(docker),1000(vagrant) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 #Confirm that the container can be started without sudo [[email protected] ~]$ docker run hello-world
https://docs.docker.jp/get-started/part2.html Dockerfile A file that predefines what to do inside the container. If you write the definition for connecting to system resources such as network in this file, The same environment can be shared by multiple users.
#Clone sample application from github [[email protected] ~]$ sudo yum -y install git [[email protected] ~]$ git clone https://github.com/dockersamples/node-bulletin-board [[email protected] ~]$ cd node-bulletin-board/bulletin-board-app/ #There is a Dockerfile! [[email protected] bulletin-board-app]$ ls app.js backend Dockerfile fonts index.html LICENSE package.json readme.md server.js site.css [[email protected] bulletin-board-app]$
#Check the contents [[email protected] bulletin-board-app]$ cat Dockerfile FROM node:current-slim WORKDIR /usr/src/app COPY package.json . RUN npm install EXPOSE 8080 CMD [ "npm", "start" ] COPY . . #Create an image!--tags is an option to name the image [[email protected] bulletin-board-app]$ docker build --tag bulletinboard:1.0 . \Sending build context to Docker daemon 45.57kB Step 1/7 : FROM node:current-slim current-slim: Pulling from library/node e50c3c9ef5a2: Pull complete 7d035f3b6068: Pull complete 1758a95126e3: Pull complete d39676814e5a: Pull complete e7aa22215d06: Pull complete Digest: sha256:7bf36131ed121f8113794e83a665bdf5d81cdf77c07672a6c1620fd71675bc8c Status: Downloaded newer image for node:current-slim ---> 9ac9e9f30b2c Step 2/7 : WORKDIR /usr/src/app ---> Running in ab0034727068 Removing intermediate container ab0034727068 ---> 2c6dc642d528 Step 3/7 : COPY package.json . ---> 8ee0076c51cb ~ Omitted ~ Step 7/7 : COPY . . ---> e614dbf84475 Successfully built e614dbf84475 Successfully tagged bulletinboard:1.0 [[email protected] bulletin-board-app]$
#Run the created image as a container [[email protected] bulletin-board-app]$ docker run --publish 8000:8080 --detach --name bb bulletinboard:1.0 82832002c212c6a6849eb079ce3bfbfe962c38245ef5407183e7b8eb64ce6a3d
docker run --publish 8000:8080 --detach --name bb bulletinboard:1.0
|--publish||Specifying port forwarding
Unless specified, communication is rejected by default.
|--detach||Run the container in the background and display the container ID
If this is not specified, the prompt in the container will be displayed.
Since the container has started, try connecting to http: // localhost: 8000 with a browser
When you are satisfied, delete the container. Since the running container cannot be deleted suddenly, stop it and then delete it.
[[email protected] bulletin-board-app]$ docker stop bb bb [[email protected] bulletin-board-app]$ docker rm bb bb
That's all for now. If you write out the contents of the Dockerfile and so on, one more article is not enough. It seems that the first post will not be possible forever without separating it somewhere, so I will separate it here.