Five, the Docker
1, the introduction of
Docker is an open source application container engine; Is a lightweight container technology;
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.
2. Core concepts
Docker Host: a machine installed with docker program (Docker is directly installed on the operating system);
Docker Client: Connects to docker host for operation;
Docker repository (Registry) : used to store various packaged software images;
Docker Images: Images packaged by software; Put in docker warehouse;
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
How to use Docker:
1) Install Docker
2) Go to Docker warehouse to find the corresponding image of this software;
3) Use Docker to run the image, the image will generate a Docker container;
4) The start and stop of the container is the start and stop of the software;
3. Install Docker
1) Install the Linux VM
1) VMWare, VirtualBox (installation);
2) Import the VM file centos7-atguigu.ova.
3) Double-click to start the Linux VM; Log in as root/ 123456
4) Use the client to connect to the Linux server for command operation;
5) Set the VIRTUAL machine network;
Bridge network = Select network card == Access network cable;
6) After setting the network, run the command to restart the VM network
service network restart
Copy the code
7), check the IP address of Linux
ip addr
Copy the code
8) Use the client to connect to Linux;
2) Install Docker on Linux virtual machine
Steps:
1. Check the kernel version 4. Start docker [root@localhost ~]# systemctl start docker [root@localhost ~]# docker -v docker version 1.12.6, Docker [root@localhost ~]# systemctl enable docker Created symlink from The/etc/systemd/system/multi - user. Target. Wants/docker. Service to/usr/lib/systemd/system/docker. Service. 6, stop the docker systemctl stop dockerCopy the code
Docker common command & operation
1) Mirror operation
operation | The command | instructions |
---|---|---|
retrieve | Docker search keyword eg: docker search redis | We often go to the Docker Hub to retrieve image details, such as the image’s TAG. |
pull | Docker pull image name :tag | : Tag Is optional. Tag indicates the software version. The default value is Latest |
The list of | docker images | View all local mirrors |
delete | docker rmi image-id | Example Delete a local mirror |
hub.docker.com/
2) Container operation
Software image (QQ setup program) —- Run image —- generate a container (running software, running QQ);
Steps:
[root@localhost ~]# docker pull [root@localhost ~]# docker pull [root@localhost ~]# docker pull --name mytomcat -d tomcat:latest 4, docker ps check whether docker is running 5, stop docker stop docker id 6, check whether docker ps -a 7, start docker [root@localhost ~]# docker run -d -p 8888:8080 tomcat -d: docker run -d -p 8888:8080 Host port: internal port of the container 10, To demonstrate simply disable Linux firewall service firewalld status; Service firewalld stop: Disable the firewall. 11. View container logs docker logs container-name/container-id https://docs.docker.com/engine/reference/commandline/docker/ can refer to each document imageCopy the code
3), install MySQL example
docker pull mysql
Copy the code
Wrong start
[root@localhost ~]# docker run --name mysql01 -d mysql 42f09819908bb72dd99ae19e792e0a5d03c48638421fa64cce5f8ba0f40f5846 [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 42f09819908b mysql "docker-entrypoint.sh" 34 seconds ago Exited (1) 33 seconds ago mysql01 538bde63e500 tomcat "catalina.sh run" About an hour ago Exited (143) About an hour ago compassionate_ goldstine c4f1ac60b3fc tomcat "catalina.sh run" About an hour ago Exited (143) About an hour ago lonely_fermi 81ec743a5271 tomcat "catalina.sh run" About an hour ago Exited (143) About An hour ago sick_ramanujan // error [root@localhost ~]# docker logs 42f09819908b error: sick_ramanujan // error [root@localhost ~]# docker logs 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 these three parameters must be specifiedCopy the code
Correct startup
[root@localhost ~]# docker run --name mysql01 -e MYSQL_ROOT_PASSWORD=123456 -d mysql
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 mysql01
Copy the code
Port mapping is performed
[root@localhost ~]# docker run -p 3306:3306 --name mysql02 -e MYSQL_ROOT_PASSWORD=123456 -d mysql ad10e4bc5c6a0f61cbad43898de71d366117d120e39db651844c0e73863b9434 [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ad10e4bc5c6a mysql "docker-entrypoint.sh" 4 seconds ago Up 2 seconds 0.0.0.0:3306 - > 3306 / TCP mysql02Copy the code
Several other advanced operations
docker run --name mysql03 -v /conf/mysql:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag /conf/mysql/mysqlDocker /conf/ mysql.conf/mysql.conf/mysql.conf/mysql.conf/mysql.conf/mysql.conf/mysql.conf/mysql.conf/mysql.conf/mysql.conf/mysql.conf/mysql.conf/mysql.conf/mysql.conf --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag --character-set-server=utf8mb4 --collation-server= UTf8MB4_unicode_ci Specifies some configuration parameters for mysqlCopy the code