1, Preface
Recently, when you open the official account, you can see the relevant contents of [cloud native], [Kubernetes engineer] and [cloud native engineer] by reading the title. Although... I will still click it to have a look. After all, I want to learn it. This technology mainly includes Kubernetes and Docker. I am familiar with Kubernetes, so I will mainly share the content of Docker learning.
I came into contact with Docker at the beginning of 2020. At that time, there was a demand for automatic crawlers. I used python to build a vnc environment with Docker. At that time, I thought it was awesome. I learned a little later, but because there was no practice opportunity, I just tasted it.
In 2021 this year, our quality team introduced MeterSphere open source automated testing platform. The other party provided a Docker deployment method, and the entire service was deployed with one command, including kafka, mysql, node and other middleware. The deployment process was too cool, and it did not need to install the software one by one. At this time, I had a deeper understanding of Docker's "Build once, Run anywhere".
Later, I planned to introduce Docker. I started to practice Docker. The process was somewhat bumpy, but the service deployment was successful in the end. At the moment when the browser opened the application page, my eyes suddenly filled with tears. Haha, there was no more. At that time, the operation and maintenance team that had been assisting me was still running away, and the team leader Bo Ge and the development teacher Huang were in a meeting. At that moment, no one shared my joy and gave me a hard hold. Hahaha.
Let's talk about the basic knowledge of Docker I have learned.
2, Docker introduction
1. What is Docker
Docker is an open source application container engine, based on the Go language and following the Apache 2.0 protocol.
Docker allows developers to package their applications and dependency packages into a lightweight and portable container, and then publish them to any popular Linux machine. It can also realize virtualization.
The container is completely sandboxed, and there will be no interface between them (similar to iPhone app s). More importantly, the performance overhead of the container is extremely low.
2. Three basic concepts of Docker
Image: Docker image is equivalent to a root file system. For example, the official image ubuntu:16.04 contains a complete set of root file systems of the smallest Ubuntu 16.04 system.
Container: the relationship between image and container is just like that of classes and instances in object-oriented programming. Image is a static definition, and container is an entity when the image is running. Containers can be created, started, stopped, deleted, paused, etc.
Repository: a repository can be regarded as a code control center for storing images.
The above is a brief introduction to Docker. For more details, please refer to [cartoon] container technology docker application scenario analysis.
At first, I was still dazzled until I read this sentence: the relationship between containers and mirrors is similar to that between objects and classes in object-oriented programming. The whole person is enlightened, that is to run the code?!
Docker containers are created through docker images.
Docker | object-oriented |
---|---|
container | object |
image | class |
Mirror warehouse Harbor | Code warehouse GitHub |
3, Installation and basic operation of Docker
Next, let's talk about how to install Docker and basic operations, including starting Docker, pulling images, running containers, and viewing images.
copy# 1. Install docker # Check the kernel version. It must be 3.10 or above uname ‐ r. if not, update the package with yum update and yum install docker # 2.1. Check whether docker is successfully installed docker -v docker run hello-world # 3.1. Start docker service docker start # 3.2. Start docker systemctl enable docker # 4.1. Set to pull image from ustc vim /etc/docker/daemon.json { "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"] } # 4.2. The docker service needs to be restarted systemctl restart docker.service # 5. View running containers docker ps -a # 6.1. Installing Tomcat # Start container in daemon background mode: docker run -d --name container name image # Access address: http://ip Address: 8888/ (ens33) docker search tomcat #Search tomcat docker pull tomcat #Pull tomcat image docker run -d --name mytomcat -p 8888:8080 tomcat:latest #Start the tomcat container and make port mapping docker ps # 6.2. Enter tomcat container docker exec -it 837b8ca7683b /bin/bash # 6.3. Unable to access Tomcat note: ll cannot be used, only ls can be used # The reason why you can't access the home page is that the folder webapps where the home page is stored is empty. tomcat of docker places these files in webapps Dist folder, just delete the empty webapps folder and rename webapps.dist to webapps # 7. View docker image docker images
4, Installing Harbor
Harbor is a mirror repository, similar to the code hosting platform github.
copywget -c https://storage.googleapis.com/harbor-releases/release-1.8.0/harbor-offline-installer-v1.8.2-rc1.tgz tar -zxvf harbor-offline-installer-v1.8.2-rc1.tgz -C /wmh/software/ #After the service is started, container services such as nginx and db are automatically created cd harbor && ./install.sh #Visit Harbor http://ip address / Harbor / sign in #Restart Harbor cd /usr/local/harbor ./prepare docker-compose down -v docker-compose up -d (If the configuration file is not modified, only execute the command, without verification) #Note: you need to enter docker compose first YML can execute docker compose PS cd /usr/local/harbor && docker-compose ps #Log in to Docker Hub docker login -u user name -p password #To upload the local image to the image warehouse, log in to the image warehouse docker push docker push myapache:v1
5, Docker graphical tool portal
We can use the portal to manage the Docker environment. Please refer to the following article for specific usage.
The Docker graphical tool Portainer must be recommended to you!
copyDownload first Portainer of Docker Mirror image; docker pull portainer/portainer Then run with the following command: Portainer Containers; docker run -p 9000:9000 -p 8000:8000 --name portainer \ --restart=always \ -v /var/run/docker.sock:/var/run/docker.sock \ -v /mydata/portainer/data:/data \ -d portainer/portainer When you log in for the first time, you need to create an administrator account. The access address is: http://ip address: 9000/
6, Summary
"Build, Ship and Run"
Build, send and operate
"Build once,Run anywhere"
Build it once and use it everywhere