SpringBoot learning notes-012

Five, Docker

5.1, introduction

Docker is an open source application container engine and a lightweight container technology;

Docker supports compiling software into an image, and then configures various software in the image to publish the image, which can be directly used by other users;

The running image is called a container, and container startup is very fast.

5.2 core concepts

Docker host: the machine with docker program installed (docker is directly installed on the operating system);

Docker client: connect to the docker host for operation;

docker warehouse (Registry): used to store various packaged software images;

Docker images (lmages): images packaged by software; placed in docker warehouse;

docker container: an instance after the image is started is called a container. A container is one or a group of applications running independently

To use Docker: 1) . install Docker 2) . go to the Docker warehouse to find the corresponding image of the software; 3) Use Docker to run the image, which will generate a Docker container; 4) , the start and stop of the container is the start and stop of the software;

5.3 installing Docker

5.3.1. Install linux virtual machine

1) , VMWare. VirtualBox (installation); 2) , import the virtual machine file centos7-atguigu.ova; 3) Double click to start linux virtual machine; log in with root/ 123456 4) Use client to connect linux server for command operation; 5) . set up virtual machine network: Bridge network = select network card = = access network cable; 6) . after setting up the network, restart the network of the virtual machine with the command

service network restart

7) , view the ip address of linux

ip addr

8) . use the client to connect to linux;

5.3.2. Install docker on the Linux virtual machine

Steps:

1,Check kernel version, must be 3.10 And above
uname -r
2,install docker
yum install docker
3.input y Confirm installation
4,start-up docker
[root@localhost ~]# systemctl start docker
[root@localhost ~]# docker -V
Docker version 1.12.6, build 3e8e77d/1.12.6
5.Boot up docker
[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/mu1ti-user.target.wants/docker.service to
/usr/1ib/ systemd/system/docker .service.
6,Stop it docker
systemctl stop docker

5.4. Docker common commands & Operations

5.4.1 image operation

operation command Explain
retrieval Docker search keyword eg: docker search redis We often go to the docker hub to retrieve the image details, such as the image TAG.
Pull out docker pull image name: tag : tag is optional. Tag indicates the label. Most of them are software versions. The default is latest
list docker images View all local mirrors
delete docker rmi image-id Delete the specified local image

https://hub.docker.com/

5.4.2 container operation

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

Steps:

1.Search mirroring
[ root@localhost ~]# docker search tomcat
2,Pull mirror image
[ root@localhost ~]# docker pull tomcat
3.Start container from mirror
docker run --name mytomcat -d tomcat:latest
4,View running containers
docker ps
5,Stopping a running container
docker stop Container id
6,View all containers
docker ps -a
7.Starting container
docker start container id
8,Delete a container
docker rm container id
9.Start a port mapped tomcat
[root@localhost ~]# docker run -d -P 888:8080 tomcat
-d:Background operation
-p:Map the port of the host to a port of the container host port:Port inside the container

10,It's closed for demonstration linux Firewall
service firewalld status ; View firewall status
service firewalld stop :Turn off firewall
11,View the container's log
docker 1ogs container-name/container-id

//For more commands, see
https://docs.docker.com/engine/reference/commandline/docker/
//You can refer to the documentation of each image

5.4.3 example of installing MySQL

docker pull mysql

Wrong start

[root@localhost ~]# docker run --name mysq101 -d mysql
42f09819908bb72dd99ae19e792e0a5d03c48638421 fa64cce5f8ba0f40f5846

mysq1 Quit
[app@eppear-server-master mysql]$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                   PORTS                               NAMES
9031366bddac        nginx               "nginx -g 'daemon of..."   3 weeks ago         Up 3 weeks               0.0.0.0:80->80/tcp                  nginx-1
00891f538a20        redis:5.0.3         "docker-entrypoint.s..."   3 weeks ago         Up 3 weeks               0.0.0.0:6379->6379/tcp              redis-1
b112853e622f        tomcat:8.5.37       "catalina.sh run"        3 weeks ago         Up 3 weeks               0.0.0.0:8080->8080/tcp              tomcat-8
e01fc3f67654        mysql:5.7           "docker-entrypoint.s..."   3 weeks ago         Up 3 weeks               0.0.0.0:3306->3306/tcp, 33060/tcp   mysql
a9938dfdb3a1        hello-world         "/hello"                 3 weeks ago         Exited (0) 3 weeks ago                                       distracted_feistel


//Error log
[root@localhost ~]# docker 1ogs 42f09819908b
error: database is uninitialized and password option is not specified
You need to specify one of MYSQL ROOT PASSWORD, MYSQL ALLOW_ EMPTY PASSWORD and
MYSQL_ RANDOM ROOT PASSWORD ;One of the three parameters must be specified

Correct startup

[root@localhost ~]# docker run --name mysq101 -e MYSQL_ROOT_PASSWORD-123456 -d mysq1
b874c56bec49fb43024b3805ab51e9097da779f2f572c22c695305dedd684c5f
[root@localhost ~]# docker ps
CONTAINER ID    IMAGE    COMMAND    CREATED    STATUS    PORTS    NAMES    
b874c56bec49    mysql    "docker-entrypoint.sh"     4 seconds ago    Up 3 seconds    3306/tcp
mysq101

Port mapping done

[root@localhost ~]# docker run -P 3306:3306 --name mysq102 -e MYSQL_ROOT_PASSWORD=123456 -d mysq1
ad10e4bc5c6a0f61cbad43898de71d366117d120e39db651844c0e73863b9434
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE      COMMAND    CREATED     STATUS     PORTS      NAMES  
ad16e4bc5c6a     mysq1        "docker-entrypoint.sh" 4 seconds ago   Up 2 seconds     0.0.0.0:3306->3306/tcp   mysq102

Several other advanced operations

docker run --name mysq103 -v /conf/mysq1:/etc/mysq1/conf.d -e MYSQL ROOT PASSWORD=my-secret-pw -d mysql:tag
 Mount the / conf/mysq1 folder of the host to the / etc/mysq1/conf.d folder of the mysqldocker container
 To change the configuration file of mysq1, you only need to put it in the customized folder (/ conf/mysq1)

docker run --name some-mysq1 -e MYSQL_ ROOT_PASSWORD=my-secret-pw -d mysq1:tag --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
 Specify some configuration parameters of mysq1

Tags: Programming Docker MySQL Linux network

Posted on Sat, 28 Mar 2020 04:19:06 -0700 by The MA