docker download and installation-image acceleration-image production

1: Docker installation

1: Check CentOS version

Currently, Docker is only supported in the kernel in the CentOS distribution. Docker runs on CentOS 7 (64-bit), which requires the system to be 64-bit and the Linux system kernel version to be 3.8 or above. Centos7.x is selected here.

cat /etc/redhat-release

Used to view version information of Red Hat series Linux distributions

 uname -r
The command is used to display the release number of the operating system

2: Make sure your virtual machine can access the Internet

ping www.jd.com or ping www.baidu.com

YUM is equivalent to a large smart warehouse that contains all components and dependency packages and can find multiple things at once. In Linux, it can solve the relationship between multiple dependency packages. For example, if you want to install a language compiler that supports c and c++, such as gcc, gcc-c++. If you want to install it using RPM, you need to install multiple dependent packages one by one, which is too tedious. Here we can use YUM to do it with one click. Installation is very easy.

Install the basic environment first.

yum -y install gcc

yum -y install gcc-c++ 

3: Install the required software packages (official website requirements)

implement:

yum install -y yum-utils

4: Set up stable mirror warehouse

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

5: Update yum package index

yum makecache fast

6: Install DOCKER CE

yum -y install docker-ce docker-ce-cli containerd.io

7: Start docker

systemctl start docker

8: Test docker

docker version

Alibaba Cloud Image Acceleration

Operation process

Just copy the configuration and run it automatically on Linux.

systemctl restart docker restart docker

Why is docker faster than a virtual machine

(1) Docker has fewer abstraction layers than virtual machines

Since docker does not require a hypervisor (virtual machine) to virtualize hardware resources, programs running on docker containers directly use the hardware resources of the actual physical machine. Therefore, docker will have obvious advantages in efficiency in terms of CPU and memory utilization.

(2) Docker uses the host’s kernel and does not need to load the operating system OS kernel.

When creating a new container, Docker does not need to reload an operating system kernel like a virtual machine. This avoids time-consuming and resource-consuming processes such as booting, loading the operating system kernel and returning. When a new virtual machine is created, the virtual machine software needs to load the OS and return to the new creation process in minutes. Since docker directly uses the host’s operating system, it omits the return process, so it only takes a few seconds to create a new docker container.

Docker common commands

·Start docker: systemctl start docker
·Stop docker: systemctl stop docker
·Restart docker: systemctl restart docker
·View docker status: systemctl status docker
·Start up: systemctl enable docker
·View docker summary information: docker info
·View the overall docker help documentation: docker --help
·View the docker command help documentation: docker specific command --help

Mirror related

# Search the image warehouse, recommended: https://hub.docker.com/ (interface)
docker search image name

# View local mirror
docker images

# Download (pull) the image, the image name format is name:version number
docker pull image name

# Delete the image (be careful)
docker rmi image name

Container related

# View local containers
docker ps # can view running containers
docker ps -a # can view all containers (running and stopped)

#Create a new container and run it (-d runs the container in the background and returns the container ID -p host port:container port specifies the mapping relationship)
docker run -d -p 8089:80 --name=container name image name

# Enter inside the container
docker exec -it container name /bin/bash /bin/bash I hope the interactive mode is shell

# View container information
docker inspect container name

# Start container
docker start container name

# Stop the container
docker stop container name

# Delete container
docker rm container name

#Delete all containers
docker rm -f $(docker ps -aq)

Example:
1. View the container docker ps -a
2. Run nginx as a container docker run -d -p 8089:80 --name=mynginx nginx
3. Enter docker exec -it mynginx /bin/bash
4. Stop docker stop mynginx
5. Delete docker rm mynginx

Docker image production

The Docker image is a layered file system. The bottom layer is bootfs, which directly uses the host’s bootfs. The second layer is the root file system rootfs, which is called base image.

Then you can superimpose other image files upwards, and one image can be placed on top of another image. The image below is called the parent image, and the bottom image becomes the base image.

Docker allows you to convert a container directly into an image using the following command:

docker commit container id image name: version number

Case: Modify the content of the index.html file in the current nginx container to hehe, and then make the modified container into a mirror named mynginx:hehe

#1. View currently running containers
[root@itcast ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0ce0bf14399d nginx "/docker-entrypoint.…" 14 hours ago Up 14 hours 0.0.0.0:80->80/tcp nginx

#2. Enter the nginx container, then overwrite and write "hehe" to the main page, and then exit the container
[root@itcast ~]# docker exec -it nginx /bin/bash
root@0ce0bf14399d:/# echo "hehe" > /usr/share/nginx/html/index.html
root@0ce0bf14399d:/# exit

#3. Generate the modified container into a mynginx:hehe image
[root@itcast ~]# docker commit nginx mynginx:hehe
sha256:139a9ea6a6008bc5557566e54316ccd8b93f508dba1daf7296235a461c8d471e

#4. View the image
[root@itcast ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mynginx hehe 139a9ea6a600 8 seconds ago 133MB

Docker downloads infulxDB time series database

docker pull influxdb
#Pull the influxdb image


#View all images
 docker images


#Start influxdb
docker run --name influxdb --restart=always -p 8086:8086 influxdb




docker logs --since 30m influxdb
--since 30m is to view the log status of this container within 30 minutes. 

Then access ip + 8086

172.17.0.1 calls the IP address in the server in the container 172.17.0.1:8080 calls the 8080 port number of the server -network host The container and the server are both on the same network segment 127.0.0.1:8080 calls the 8080 port number of the server

127.0.0.1 calls the address in the container. Private system 8080 8090 127.0.0.1:8080 calls 8080 in the container.

Docker enters the mysql command:


<code>docker exec -it <container ID or name> /bin/bash</code>
<code>mysql -h localhost -u <username> -p</code>

Illustration of what dodocekr run does

The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge. Cloud native entry-level skill treeContainer (docker)Install docker16970 people are learning the system