Docker introduction also uses

Posted by davidtube on Thu, 02 Jan 2020 15:06:48 +0100

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/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
6,Stop it docker
systemctl stop docker

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

10. The firewall of linux is simply closed for demonstration
Service firewall status; view firewall status
Service firewall stop: turn off the firewall
11. View the container's log
docker logs 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

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

mysql Quit
[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 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

Real start

[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

Do port mapping

[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 operations

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

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

Topics: Docker MySQL Tomcat firewall