Spring Boot's personal notes from 0 to learn 5 - Docker

1. Introduction

The following are to install a virtual machine in the window, then open the Linux system, and then install SmarTTY, which is used inside

For example, if we want to install Windows, we must download the system, then download the driver, software and various things, and then package them into a mirror. Others can use the Windows system, drivers, and software with the mirror. Docker is also a similar idea, but it is not a system, but a variety of software, and it is a lightweight container. Container, then it can be easily placed in Java, and it starts quickly.

Docker mainly has the following things

  • Docker host (Host): the machine where the Docker program is installed (Docker is installed directly on the operating system);
  • docker client (Client): connect to the docker host for operation;
  • Docker warehouse (Registry): used to store various packaged software images;
  • Docker image (Images): software packaged image; placed in the docker warehouse;
  • Docker container (Container): The instance after the image is started is called a container; the container is an application or a group of applications that run independently

Steps:
1), install Docker

2) Go to the Docker warehouse to find the mirror image corresponding to this software;

3) Use Docker to run this image, this image will generate a Docker container;

4) The start and stop of the container is the start and stop of the software;

Second, install Docker

Preparation steps

Install Docker:

1、检查内核版本,必须是3.10及以上
uname -r
1.1、更新内核
tum update
输入y确认安装

1.2、重启Linux
reroot

2、安装docker
yum install docker

3、输入y确认安装

4、启动docker
[root@localhost ~]# systemctl start docker
[root@localhost ~]# docker -v
Docker version 1.12.6, build 3e8e77d/1.12.6

5、开机启动docker
[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

6、停止docker
systemctl stop docker

Insert picture description here

Three, Docker common operations

Insert picture description here
Mirror operation:
Insert picture description here

1. Add a domestic accelerator

https://blog.csdn.net/weixin_43569697/article/details/89279225
https://www.cnblogs.com/spll/p/11828193.html

cd /etc/docker
cat daemon.json
Insert picture description here
The picture shows a bit wrong. .
Insert picture description here

Insert picture description here

sudo systemctl daemon-reload//重新加载
sudo systemctl restart docker//重启

2. Operation

Software image (QQ installer) ---- run image ---- generate a container (running software, running QQ);

step:

1、搜索镜像
[root@localhost ~]# docker search tomcat
2、拉取镜像
[root@localhost ~]# docker pull tomcat
3、根据镜像启动容器
docker run --name mytomcat -d tomcat:latest
4、docker ps  
查看运行中的容器
5、 停止运行中的容器
docker stop  容器的id
6、查看所有的容器
docker ps -a
7、启动容器
docker start 容器id
8、删除一个容器
 docker rm 容器id
9、启动一个做了端口映射的tomcat
[root@localhost ~]# docker run -d -p 8888:8080 tomcat
-d:后台运行
-p: 将主机的端口映射到容器的一个端口    主机端口:容器内部的端口

10、为了演示简单关闭了linux的防火墙
service firewalld status ;查看防火墙状态
service firewalld stop:关闭防火墙
11、查看容器的日志
docker logs container-name/container-id

更多命令参看
https://docs.docker.com/engine/reference/commandline/docker/
可以参考每一个镜像的文档

1) Search mirror

The following example changes mysql to tomcat, which is a mistake. . . .
What docker search looks for
Insert picture description here

2) Download the mirror

docker pull mysql what to download
Insert picture description here

3) View the mirror

The
Insert picture description here
above two examples of docker images are wrong. . . Should download tomcat. . Then change mysql to tomcat

4) Run the mirror

docker run --name 自己起的容器名字 -d 要用哪个镜像 Among them, -d means running in the background
Insert picture description here

5) Check which images are starting

docker ps
Insert picture description here

6) Start a tomcat with port mapping

docker run -d -p 8888:8080 tomcat, Will generate a new tomcat

  • -d: run in the background
  • -p: map the port of the host to a port of the container host port: the port inside the container
  • 8888:8080: Map 8888 to 8080

7) Visit tomcat

A tomcat is generated
Insert picture description here
on the browser to visit http://192.168.0.102:8888/, that is my IP,
Insert picture description here
this is not an error, but the new version has changed, and the home page has changed.

Four, fixed IP

1. A serious approach

It’s such a pit, my teacher didn’t say that it’s a pitfall.
If it’s not fixed, the IP address of your virtual machine will change after a period of time. Then SmarTTY runs docker based on the IP connection, but the IP has changed. You can't connect, so we need to fix the IP address in the virtual machine.
Refer to the article. The
main thing is to IPADDR=192.168.0.102change this. This IP is changed to the IP of the SmarTTY connection, so that the fixed will not change.

2. The way of ghosts

The above method has been used but I forgot how to do it. . .
Therefore, the address of the virtual machine is limited to 128-129, and the occupancy time is 60 days. In this way, the 60-day period of switching back and forth, and the other ones only need to do the two IP corresponding interfaces.

Edit-Virtual Network Compiler-Change more advanced settings (forgot what it is, anyway, it needs administrator privileges to do it)
Insert picture description here

Guess you like

Origin blog.csdn.net/yi742891270/article/details/107486910