Docker is an open source application container engine, which is based on the Go language and conforms to the Apache2.0 protocol. Docker allows developers to package their applications and dependencies into a lightweight, portable container for distribution on any popular Linux machine, as well as virtualization. Containers are completely sandboated, there is no interface between them (similar to an iPhone app), and more importantly, the container performance overhead is extremely low. All operations in this article operate on Centos7

Installation and startup

# a, install the Docker curl - sSL # https://get.daocloud.io/docker | sh using domestic daocloud one-click install command: Docker # *systemctl* is the system service manager directive, which is a combination of two commands: service and chkconfig. Docker systemctl restart docker systemctl restart docker systemctl Docker -- docker -- docker -- docker -- docker -- docker -- docker -- docker -- docker

Permission issues handling

Some permission errors may occur while manipulating the image

# error:  Got permission denied while trying to connect to the Docker daemon socket at unix:///var/ sudo gpasswd -a username Newgrp docker # update docker # update docker # su is not in the sudoers file # su is not in the sudoers file # su is not in the sudoers file # su is not in the sudoers file # su The working directory is still the working directory of the normal user. # su - The user and the Shell environment have been switched to root. The PATH environment variable error does not occur until the Shell environment is switched. The PWD working directory is now root's working directory. Visudo # Remember, there is no space between vi and sudo. Add: your_user_name ALL=(ALL) ALL. Save the sudo command, which adds you to the sudo group

The mirror

Docker images # lists images. These images are stored in /var/lib/docker on the Docker host. The name of the Docker search image is # search image. Docker rmi $IMAGE_ID # delete docker rmi 'docker image-q' # delete all images # /etc/docker/daemon.json: If the file does not exist, create it manually  {"registry-mirrors":["https://docker.mirrors.ustc.edu.cn"]} # {"registry-mirrors":["https://hub.daocloud.io"]} # Systemctl daemon-reload systemctl restart docker

The container

Docker ps -- a docker ps -- l docker ps -- l docker ps -- l docker ps -- l docker ps -- l docker ps -- l docker ps -- l docker ps -- l docker ps -- f status=exited # # -i: to run a docker # -t: to run a docker # -i: to run a docker # -t: to run a docker # -t: to run a docker # -i: to run a docker # -t: to run a docker # When you add these two parameters, the container is created and you can log in. That is, a pseudo-terminal is assigned. # --name: Name the container you created. # -v: Indicates a directory mapping relationship (after -v is the host directory: container directory). Multiple -v can be used to map multiple directories or files. Note: It is best to do directory mapping, make changes on the host, and then share them on the container. # -d: If you add -d to the end of the "run" parameter, a daemon container will be created to run in the background. (If you add -i -t to the end of the "run" parameter, then a daemon container will be created.) # -p: indicates port mapping (after -p is host port: container port). Docker run-it --name=mycentos1 centos:7 # docker run-it --name=mycentos1 centos:7 # docker run-it --name=mycentos1 centos:7 # Guardian type container docker exec - it container_name (or container_id)/bin/bash guard type container # onto the # using the exit command to exit the current container # 3, stop and start the container docker stop $CONTAINER_NAME/ID $CONTAINER_NAME/ID $CONTAINER_NAME/ID $CONTAINER_NAME/ID $CONTAINER_NAME/ID When we create a container, we can map the host's directory to the directory inside the container. When we create a container, we can map the host's directory to the directory inside the container. This allows you to affect the container by modifying files in a directory on the host. If you are sharing multiple levels of directories, you may be prompted with insufficient permissions. This is because SELinux, the security module in Centos7, disallows permissions. We need to add parameters - ring = true to solve the problem of mount directory without permission docker run - di - v/usr/local/myhtml: / usr/local/myhtml - name = mycentos2 Centos: 7 # 6, view the IP address docker inspect mycentos2 # to check the container to run the various data docker inspect - format = '{{. NetworkSettings. IPAddress}}' Docker rm $CONTAINER_ID/NAME # delete CONTAINER_ID from docker rm $CONTAINER_ID Rm 'docker' docker ps-a-q '# delete all containers:

The deployment of application

1 MySQL deployment

Mysql > docker run-di --name= mysql-p 33306:3306-e mysql > docker run-di --name= mysql-p 33306:3306-e MYSQL_ROOT_PASSWORD=123456 MYSQL_ROOT_PASSWORD=123456 MYSQL_ROOT_PASSWORD = 'docker exec-it' mysql /bin/bash mysql-u = 'docker exec-it' mysql /bin/bash mysql-u = 'docker exec-it' Root-p # mysql > mysql

2 tomcat deployment

Docker run-di --name= tomcat-p 9000:8080-v docker run-di = tomcat-p 9000:8080-v / usr/local/myhtml: / usr/local/tomcat/webapps - ring = true tomcat: 7 - jre7 # - v address mapping

Deploy Web applications. Modify the CAS system configuration file and modify the URL of the database connection

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" p:driverClass="com.mysql.jdbc.Driver" P: jdbcUrl = "JDBC: mysql: / / 172.17.0.6:3306 / andydb? characterEncoding=utf8" p:user="root" p:password="123456" />

Test: the address bar: http://192.168.247.135:9000/cas/login

3 Nginx deployment

Docker run-di --name= nginx-p 80:80 Nginx /bin/bash # test Nginx Your browser's address bar: http://192.168.247.135 # copies configuration files from the container to hosting docker cp nginx: / etc/nginx/nginx. Conf nginx. Conf

Edit nginx.conf to add the reverse proxy configuration

Upstream tomcat-cas {server 172.17.0.7:8080; } server { listen 80; server_name passport.andy.com; location / { proxy_pass http://tomcat-cas; index index.html index.htm; }}
# modified configuration file copy to container docker cp nginx. Conf nginx: / etc/nginx/nginx. Conf # to restart the container docker restart pinyougou_nginx # set the domain name to, The host file: 192.168.247.135 passport.andy.com # browser testing: http://passport.andy.com/cas/login

4 Redis deployment

Docker run-di --name= redis-p 6379:6379 Redis Windows version Redis: Redis-cli-h 192.168.247.135

Backup and migration

Docker commit nginx to mynginx with the name of the container and mynginx with the name of the container Next you can use this image to run the new container again # mirror-backup docker save -o mynginx.tar mynginx # -o output to file # after execution, Mysql > restore the file docker load -i mynginx.tar # -i file to restore the file docker load -i mynginx.tar # -i file to restore the file You can see that the image has been restored