This article has participated in the good article call order activity, click to see: back end, big front end double track submission, 20,000 yuan prize pool for you to challenge!

Disable the firewall and selinux

[root@docker-server ~]# setenforce 0 [root@docker-server ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config Selinux [root@docker-server ~]# systemctl stop firewalld [root@docker-server ~]# systemctl disable firewalld // Do not enable the firewallCopy the code

Obtaining MySQL Image

[root@docker-server ~]# docker run-d -p 3306:3306-e MYSQL_ROOT_PASSWORD=***** --name my_mysql mysql:latestCopy the code

Error:

/usr/bin/docker-current: Error response from daemon: driver failed programming external connectivity on endpoint my_mysql (081b3190954fe7630862d408c19c4758f4e7ad0ccac073cd0c3f7686185ec914): Error starting userland proxy: listen tcp 0.0.0.0:3306: bind: address already in use.

Netstat -nap Checks the PID running the program and finds that port 3306 is occupied

netstat -nap | grep 3306
Copy the code

You can kill PID, kill the process, and restart the container

​
[root@VM-0-7-centos ~]# docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=wucs@123 --name my_mysql mysql:l               atest
Copy the code

Error:

Error response from daemon: Conflict. The container name “/my_mysql” is already i n use by container 278ba9681117783b217d8c41c3f4045cec8d23124277ac571d6abee852430311. You have to remove (o r rename) that container to be able to reuse that name..

View all containers docker ps -a

[root@VM-0-7-centos ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS P ORTS NAMES 278ba9681117 mysql:latest “docker-entrypoint…” 10 minutes ago Created my_mysql

The original launch container error, but also started

// Let's delete the my_mysql container, [root@VM-0-7-centos ~]# docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=wucs@123 --name my_mysql mysql:latestCopy the code

Success!

Parameter description:

-p Add port mapping between the host and the container -e set environment variables. Here set the initial password of user root. – Name Specifies the container name

Example Modify the mysql configuration file

[root@VM-0-7-centos ~]# docker cp my_mysql:/etc/mysql/my.cnf /opt/ edit /etc/mysql/my.cnf // Import the configuration file to the mysql container [root@VM-0-7-centos ~]# docker cp /opt/my.cnf my_mysql:/etc/mysql/Copy the code

Get the PHP 7.2 image

[root@VM-0-7-centos ~]# docker pull PHP :7.2-fpm // Start container [root@VM-0-7-centos ~]# docker run -d -v : / var/nginx/WWW/HTML/var/WWW/HTML - p, 9000:9000 - link my_mysql: mysql - name my_phpfpm PHP: 7.2 - FPMCopy the code

Parameter description: – d let container to run in the background – p – v host is added to the container port mapping add directory mapping, host/var/nginx mapped to the inside of the container/WWW/HTML/var/WWW/HTML, if the host without this directory will create the directory, or other directory mapping, The name of the container is the same as the name of the container. The name of the container is the same as the name of the container. The name of the container is the name of the container

Testing directory Mapping

Create a PHP test page in the /var/nginx/ WWW/HTML directory on the host, which maps directly to the container

[root@VM-0-7-centos ~]# cat > /var/nginx/www/html/index.php <? phpinfo(); ? > // After the input is complete, press Ctrl+D [root@VM-0-7-centos ~]# docker exec -it 3e6139bb4d5b /bin/bash // to enter the container Root @ 3 e6139bb4d5b: / var/WWW/html# ls / / ls check file, // Exit the container by running the command exit or Ctrl+P+Q [root@VM-0-7-centos ~]# exitCopy the code

The cat command:

1. Display the entire file at once: catFilename2. Create a file from the keyboard: catfilename2. To create a file from the keyboard: catFilename2. To create a file from the keyboard: cat > filename You can only create a new file, but cannot edit an existing file. After entering the file, press Ctrl+D. $cat file1 file2 > file = $cat file1 file2 > file -n or –number starts with 1. -b or –number — nonblank is similar to -n, except that blank lines are not numbered. -s or — number-blank When there are more than two consecutive blank lines, Just replace it with a blank line – V or –show-nonprinting

PHP Extension installation

Installing PHP – redis

// We exit the container, [root@VM-0-7-centos ~]# docker exec -it 3e6139bb4d5b /bin/bash pecl install redis && docker-php-ext-enable redis //enable igbinary serializer support? [no] : no //enable lzf compression support? [no] : no //enable zstd compression support? [no] : no //.... Omit... Installation is complete root @ 3 e6139bb4d5b: / var/WWW/html# PHP -m / / see what/PHP Modules installed Core ctype curl date dom the fileinfo filter FTP hash iconv json libxml mbstring mysqlnd openssl pcre PDO pdo_sqlite Phar posix readline redis Reflection session SimpleXML sodium SPL sqlite3 standard tokenizer xml xmlreader xmlwriter zlib [Zend Modules]Copy the code

Modify the PHP configuration file

[root @ VM - 0 to 7 - centos ~] # 3 e6139bb4d5b: docker cp/usr/local/etc/PHP/PHP ini - development/opt/editor/opt/PHP. Ini - development And rename for PHP. Ini / / modified import to PHP configuration file container [root @ VM - 0 to 7 - centos ~] # docker cp/opt/PHP. Ini 3 e6139bb4d5b: / usr/local/etc/PHP /Copy the code

Get the Nginx image

[root@VM-0-7-centos ~]# docker run -d -p 80:80 --name my_nginx -v /var/nginx/www/html:/var/www/html --link my_phpfpm:phpfpm --name my_nginx nginx:latestCopy the code

Parameter Description -d Makes the container run in the background. -p Adds a port mapping to the container. -v Adds a directory mapping, where the root directory of the nginx container is best written as the root directory of the PHP container. However, it does not have to be the same. If not, you need to pay attention when configuring nginx. -name the name of the container -link the connection between the containers

Modify the nginx configuration to support PHP

In this example, copy the configuration file and import it.

[root@VM-0-7-centos ~]# docker cp f998f1827420:/etc/nginx/conf.d/default.conf /opt/ [root@VM-0-7-centos ~]# vim /opt/default.conf server { listen 80; server_name localhost; location / { root /var/www/html; // Change the default path here: index index. HTML index.htmi index. PHP; } error_page 500 502 503 504/50x.html; error_page 500 502 503 504/50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ .php$ { root html; fastcgi_pass 3e6139bb4d5b:9000; // Select * from 'fastcgi_index'; // Select * from 'fastcgi_index'; fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name; // Change the path to include fastcgi_params; // Import the configuration file to the nginx container [root@VM-0-7-centos ~]# docker cp /opt/default.conf f998f1827420:/etc/nginx/conf.d/default.confCopy the code

Go into the container and reload the configuration file

[root@VM-0-7-centos ~]# docker exec -it f998f1827420 /bin/bash root@f998f1827420:/# nginx -t the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful root@f998f1827420:/# nginx -s reload 2021/06/25 09:08:12 [notice] 37#37: signal process startedCopy the code

Parameters that

-t Produces a pseudo terminal in the container. -I interacts with the STDIN in the container

View ports mapped to all containers

[root@VM-0-7-centos ~]# ss -anlt State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 129 128 *:8000 *:* LISTEN 0 50 *:3306 *:* LISTEN 0 128 *:8080 *:* LISTEN 0 128 *:80 *:* LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:*  LISTEN 0 128 [::]:9000 [::]:* LISTEN 0 128 [::]:3306 [::]:* LISTEN 0 128 [::]:8080 [::]:* LISTEN 0 128 [::]:80 [::]:* LISTEN 0 100 [::1]:25 [::]:*Copy the code

Visit the test page index.php

Enter the server IP address in the browser. If you can see phpInfo (), the deployment is successful!

✿✿ angry (°▽°) blue, (°▽°) blue

Docker basic commands

Container lifecycle management – docker [run | start | stop | restart | kill | rm | pause | unpause]

Container operation operations – docker [ps | inspect | top | attach | events | logs | wait | export | port]

Container rootfs command – docker [commit cp | | diff]

Mirror warehouse – docker [login | pull | push | search]

Local image management – docker [images | rmi | tag | build | history | save | import]

Other commands – docker [info | version]

Firewall -cmd –zone=public –add-port=3307/ TCP –permanent

The firewall-cmd –reload # configuration takes effect immediately

firewall-cmd –zone=public –list-ports