Docker installation and operation (VM + linux system)

## 1 Introduction

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

Docker support software will compile into a mirror; then do a variety of software configuration in the mirror, the mirror will release out, other users can directly use this image;

This operation is called mirroring container, the container starts very fast.

![image](51B0AFA725E04352A73AE972DA017308)


![image](72D7B811B71340179D0593B96BA873B4)

## 2, the core concept

docker host (Host): Docker machine installed program (Docker mounted directly on top of an operating system);

docker client (Client): docker host connection operation;

docker warehouse (Registry): used to store a variety of packaged software image;

docker mirror (Images): packaged software image; docker in the warehouse;

docker container (Container): Examples of the image starts is called a container; is a container or a group of applications run independently
[image] (612252E691004B66BB74420F37A3BA8A)!

Docker using the steps of:

1), the installation Docker

2), Docker warehouse to find the software corresponding to the image;

3) using Docker run this image, this image will generate a Docker containers;

4) Start to stop the vessel is to start the software stops;

## 3 installation Docker

#### 1), install linux virtual machine

1), VMWare, VirtualBox (installed);

2) introducing the virtual machine file centos7-atguigu.ova;

3) Double-click to start linux virtual machine; use root / 123456 landing

4) using a client server connection linux command operation;

5), set the virtual machine network;

=== ==== selected bridge network access network line card;

6), set up after the network using the network command to restart the virtual machine

```shell
service network restart
```

7) Check the ip address linux

```shell
ip addr
```

8), using the client connected Linux;

#### 2), mounted on a docker linux VM
! [Image] (1CD0B8F76ED84750A1975563A40E223E)

step:

`` shell `
1, check the kernel version must be 3.10 or above
uname -r
note that this upgrade should have checked it, otherwise easily lead to incompatibilities service did not start the
yum Update
2, installation Docker
// some linux yum can not be used, use the install Docker GET-APT
yum the install Docker
. 3, the input y to confirm installation
4, starting Docker
// some Docker start-Service
[the root @ localhost ~] # systemctl start Docker
[the root @ localhost ~] -v # Docker
Version 1.12.6 docker, Build 3e8e77d / 1.12.6
. 5, boot Docker
[the root @ localhost ~] # systemctl Docker enable
the Created from /etc/systemd/system/multi-user.target.wants/docker.service to the symlink / usr / lib / systemd / System / docker.service.
. 6, stop Docker
systemctl sTOP Docker
`` `

## 4, Docker common operation command &

### 1), the mirror operation

| Operations | command | Description |
| ---- | ------------------------------------- ---------- | --------------------------------------- ----------------- |
| retrieve | docker search keywords eg: docker search redis | we often go docker detailed information retrieval on the mirror hub, such as mirroring of TAG. |
| Pull | docker pull mirroring name: tag |: tag is optional, tag represents the label, multi-version software, the default is Latest |
| List | docker images | View all local mirror |
| delete | docker rmi image -id | delete the specified local mirror |

https://hub.docker.com/

### 2), container operations

Mirroring software (QQ Setup) ---- ---- generates a run-time image of the container (running software, running QQ);

step:

the shell `` ``
. 1, the search image
[the root @ localhost ~] Search # Docker Tomcat
2, the mirror pulling
[the root @ localhost ~] # Docker pull Tomcat
. 3, the mirror starting container according
docker run --name mytomcat -d tomcat: Latest
4, Docker PS
Check the operation of the vessel
5, vessel stopped running
docker stop container of the above mentioned id
6, to see all the container
Docker PS -a
7, start the container
docker start container the above mentioned id
8, to delete a container
docker rm container the above mentioned id
9 start tomcat do a port mapping
[root @ localhost ~] # Docker rUN -d -p 8888: 8080 tomcat
-d: background
-p: the host port mapping to port a container port on the host: the interior of the container port

10, to demonstrate a simple closed linux firewall
service firewalld status; see firewall status
service firewalld stop: turn off the firewall
11, to view the container log
docker logs container-name / container- id

Referring more commands
https://docs.docker.com/engine/reference/commandline/docker/
reference may be a mirror image of each document

````

 

### 3), the installation example MySQL

```shell
docker pull mysql
```

 

False start

```shell
[root@localhost ~]# docker run --name mysql01 -d mysql
42f09819908bb72dd99ae19e792e0a5d03c48638421fa64cce5f8ba0f40f5846

mysql退出了
[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 log
[root @ localhost ~] # Docker logs 42f09819908b
error: Database uninitialized IS IS not the Option and password specified
by You need to the Specify One of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD; the three parameters must specify a
`` `

The right start

```shell
[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
```

Port mapping

```shell
[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 mysql02
```

 

Several other high-level operations

`` `
Docker --name mysql03 -v /conf/mysql:/etc/mysql/conf.d RUN = -e MYSQL_ROOT_PASSWORD Secret-My-PW -d MySQL: Tag
the host / conf / mysql folder mount /etc/mysql/conf.d mysqldocker file folder inside the container
changes of the configuration file mysql just need mysql configuration file in the file folder to customize (/ conf / mysql)

docker run --name some-mysql -e MYSQL_ROOT_PASSWORD = my-secret-pw -d mysql: --character-set-server = --collation server-= utf8mb4_unicode_ci utf8mb4 tag
configuration parameters specify the mysql
`

Guess you like

Origin www.cnblogs.com/guoyinghome/p/11199785.html