@TOC
Recommend personal Docker articles, very detailed
【 Docker container 1】Docker details and installation
Build Jdk, Mysql, Nginx, Redis, Tomcat environment based on Docker in one minute
Deploy the SpringBoot project based on Docker
【 Docker container 4】 Build Docker private server based on Docker, and how to use Docker private server details
How to build Maven private server based on Docker, and how to use Maven private server
Build GitLab management code based on Docker
Automatic construction, deployment, testing and monitoring of projects based on Docker installation Jenkins
1. The Docker – introduction
Docker official website: docs.docker.com/ English address Docker Chinese website: www.docker.org.cn/ Chinese address
Docker is a cloud open source project based on Go language. It was born at the beginning of 2013 and the initial initiator is dotClouw company. Docker has been widely concerned and discussed since its open source. At present, there are several related projects, gradually forming an ecosystem around Docker. DotCloud later changed its name to Docker Ine.Docker is an open source container engine that helps deliver applications faster. Docker can isolate the application and infrastructure layers and manage the infrastructure as if it were a program. Using Docker can package, test, and deploy applications faster, and shorten the cycle from writing to deploying running code.
2. Why Docker
In the process of our development and operation and maintenance, we often need to install various environments on the Linux server, such as MySQL, Redis, Tomcat and other environments, so how do we install these environments on the Linux server? If you want to install MySQL, you need to go to the official website of MySQL to download the Linux installation package of MySQL. After installing MySQL, you can configure the related environment, and then install Redis, Tomcat and other environments in a similar way. Thus, the construction of the Linux environment will come to an end temporarily. One day, if we need to install MySQL, Redis, Tomcat, etc. on another Linux server, we will have to go through the same process again, which is still too much trouble. So is there an easier way? Yes, use Docker.
Docker is support for you have installed and configured the environment (such as MySQL), packaged into an image file such as mysql-Docker image. For example, Zhang SAN packages his installed and configured MySQL into an image file. If Li Si wants to install MySQL for his Linux server, he only needs to install Docker on his Linux server, and then use Docker to run the packaged MySQL image file of Zhang SAN, and finally generate MySQL container. This way we can quickly set up a Linux server environment.
3. Summary
Docker supports compiling software into an image; Then in the image of a variety of software configuration, the image released, other users can directly use this image;
The image in action is called the container, and container startup is very fast. And now all major cloud computing platforms support Docker container technology, such as Baidu Cloud, Ali Cloud and Tencent Cloud. So it is necessary for us to learn about Docker.
In short, Docker implementation can be convenient and quick installation environment, as well as fast packaging, testing and deployment of applications
For example, using Docker can achieve second level installation of mysql, JDK and other environments, such as my previous article installation of mysql is very complex, to configure a variety of things, using Docker can completely simplify the installation (custom configuration will need to do it yourself)
4.Docker- Core Concept
1. Docker Host: a machine installed with docker program (Docker is directly installed on the operating system);
As shown in the figure above, Local host is the local machine, that is, Docker program is installed on the local machine, which is the Docker host. In addition, we can also install Docker program on the remote host remote machine. Docker host can run Docker image generated Docker container.
Docker Client: the Client connects to the Docker host through the command line or other tools for operation; Similarly, we use SQLyog client to connect to MySQL server to operate MySQL.
Docker Registry: used to store all kinds of packaged software images;
4. Docker Images: Images packaged by software; Put in docker warehouse;
5. Docker Container: after the image is started, the instance is called a Container. A container is a single application or group of applications that run independently.
Basic process: If there are three configured images of MySQL, Nginx, Tomcat and Redis in the Docker warehouse, then we download these images to the local host and use the Docker command to act these images. After the image runs, the corresponding container will be generated. For example, we download the MySQL image from the Docker repository, go to the local host, and then run the MySQL image using the Docker command. After running the image, a MySQL container will be started (just like starting a MySQL). Docker Container: an instance of an image is called a Container after it is started. A container is a single application or group of applications that run independently.
5. How to use Docker
- Install the Docker
- Go to the Docker warehouse to find the image corresponding to this software (equivalent to the application market, download the installation package)
(it can be a public image or a private image file); 3. Use Docker to run the image, the image will generate a Docker container (equal to the installation software) (each container is independent, equal to each software is independent) 4. Stopping the container is stopping the software;
- Or create a custom project image and upload it to the Docker Bub repository for yourself or others to use next time
In short, the purpose of Docker is to build everywhere at once
6. Docker architecture
Docker-host (usually Linux) can communicate with DOCKER clients.
Docker Client is a Docker user interface that can accept user commands to communicate with the Docker Daemon. In the figure, Docker build, Docker pull, docker run and other commands are related to docker.
A Docker image is a read-only template that contains instructions for creating a Docker container. It is a bit like the system installation CD, using the system installation CD can install the system, similarly, using the Docker image can run Docker image in the program.
Containers are running instances of images, and a container can be called an application
Docker Registry is a service that centrally stores and distributes images. It can be called application market. After Docker image is built, it can run on the current host. But if you want to run the image on another machine, you need to manually copy it. At this point, you can use The Docker Registry to avoid manual copying of the image.
A Docker Registry can contain multiple Docker repositories, each repository has labels that can contain multiple Images, and each image can be run as a container example.
2. Install docker on Linux
Docker is an open source commercial product available in two versions: Community Edition (CE) and Enterprise Edition (EE). The Enterprise edition includes some paid services that individual developers generally don’t use
Docker requires a CentOS kernel version of 3.10 or later. Check the prerequisites on this page to verify whether your CentOS version supports Docker.
1. Run the uname -r command to check your current kernel version
uname -r
Copy the code
2. Log in as user root. Make sure the YUM package is up to date
yum -y update
Copy the code
It might take a while, but that’s fine
3. Uninstall the old version if you have installed it before.
yum remove docker docker-common docker-selinux docker-engine
Copy the code
4. Install dependencies
To prevent errors, yum-util provides yum-config-manager functionality, the other two being dependent on the Devicemapper driver
yum install -y yum-utils device-mapper-persistent-data lvm2
Copy the code
5. Configure the yum source
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Copy the code
6. You can view all docker versions in all warehouses and select a specific version to install
yum list docker-ce --showduplicates | sort -r
Copy the code
7. Install Docker
Sudo yum install -y docker-ce #Copy the code
8. Start and join boot
systemctl start docker
systemctl enable docker
Copy the code
9, verify whether the installation is successful (there are two parts of client and service, indicating that docker installation and startup are successful)
docker version
Copy the code
Success!
3. Common Docker commands
Docker basic commands
Docker version (Viewing the version) systemctl start docker (starting the docker) systemctl restart docker (restarting the docker) systemctl stop docker (Stop Docker)
Docker 1, docker install package: Yum list installed | grep docker. 2, delete the installation package yum remove docker – ce. X86_64 docker – ce – cli. X86_64 – y 3, remove the mirror rm – such as rf/container /var/lib/docker
Docker image basic commands
Docker pull image name: docker pull image name: docker pull image name: docker pull image name: docker pull image name: docker pull image name: docker pull image name: Default is latest docker images docker IMAGES
Docker container basic commands
Docker ps — A docker rm Container ID docker logs Container ID/container name docker execit Container ID Bash (enter the container) exit (exit the container)
Docker start command, Docker run and Docker start
Docker run is a two-step operation: put the image into the container (docker create), and then start the container to become a runtime container (Docker start).
Docker run –name User-defined container name -d image template (Example: docker run –name redis -d redis. – d is expressed as the background, without default startup for the front desk) -d docker stop containers id or name (stop you currently running container) docker start containers id or name (start the container)
Docker port mapping
Port mapping: Docker container and Linux system ports are one inside and one outside, so they need to be mapped to ports of external Linux system. Otherwise, they can only be used in containers
-p 6379:6379 Example: Docker run -d -p 6379:6379 –name redis
The first port number is the Linux port number, and the second port number is the container internal port number