In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
First, prepare the environment
About the installation of docker can refer to the introduction of Docker and installation configuration details here will not be introduced!
Case requirements:
(1) each container needs to achieve data persistence.
(2) assign a fixed IP address to the container to prevent the IP address from changing after the container is rebuilt, causing unnecessary trouble
Case environment:
Just install it on a docker host! The default environment is shown in the figure:
2. Case implementation (1) create a network card and solve the fixed IP address [root@docker] # docker network create-d bridge-- subnet 200.0.0.0 lnmp// to create a network card lnmp, and specify a network segment 200.0.0.0.0.1 lnmp// to solve the directory problem in the nginx container [root@docker ~] # docker run-itd-name test nginx / / run any container. In order to generate the configuration file needed in nginx [root@docker ~] # mkdir / data/ wwwroot// create directory for mounting nginx container [root@docker ~] # docker cp test:/etc/nginx / data// copy the nginx home directory in the nginx container to the local [root@docker ~] # docker cp test:/usr/share/nginx/html / wwwroot// copy the web page root directory in the nginx container to the local (3) shipping Line Nginx container test [root@docker ~] # docker run-itd-- name nginx-v / data/nginx:/etc/nginx-v/wwwroot/html:/usr/share/nginx/html-p 80:80-- network lnmp-- ip 200.0.0.10 nginx:latest// run a container named nginx Mount the corresponding directory And map the port, specify the IP address [root@docker ~] # echo "hello world" > / wwwroot/html/index.html [root@docker ~] # curl 127.0.0.1hello world// test nginx web page root directory is no problem (4) run the mysql container [root@docker ~] # docker run-itd-- name mysql-e MYSQL_ROOT_PASSWORD=123456-p 3306RV 3306-network lnmp-ip 200.0.20 mysql:5.7// run a container called mysql And specify the mapping port and IP address / / use the "- e" option to configure the environment variables in the container, which is equivalent to ENV [root@docker ~] # yum-y install mysql / / Local download mysql client tool in dockerfile to test [root@docker ~] # mysql-u root-p127.0.0.1-P 3306MySQL [(none)] > create database lzj / / Log in to the database and create the database for testing (5) run the PHP container [root@docker] # docker run-itd-- name phpfpm-p 9000-v / wwwroot/html:/usr/share/nginx/html-- network lnmp-- ip 200.0.0.30 php:7.2-fpm// run a container named phpfpm, map the port, mount the corresponding directory, specify the IP address / / see the mounted directory is the same as the nginx home directory Because you need to modify the configuration file of the nginx container [root@docker ~] # echo "> / wwwroot/html/test.php / / create a page for testing the connection between nginx and php (6) Edit the configuration file of Nginx so that Nginx can connect with php [root@docker ~] # vim / data/nginx/conf.d/default.conf 8 location / {9 root/ usr/share/nginx/html 10 index index.php index.html index.htm; / / add index.php 11} 30 location ~\ .php$ {31 root / usr/share/nginx/html; / / modify its web page root location 32 fastcgi_pass 200.0.0.30 php$ 9000; / / change to the IP address 33 fastcgi_index index.php of the PHP container 34 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; / / add the $document_root variable 35 include fastcgi_params; 36} [root@docker ~] # docker restart nginx / / restart the nginx container [root@docker ~] # docker ps | grep nginx / / ensure that the nginx container is a normal e000ccd5c883 nginx:latest "nginx-g 'daemon of …" 27 minutes ago Up 31 seconds 0.0.0.0 80/tcp nginx 80->
Access Test:
(7) Test the coordination between PHP container and Mysql container
We use phpMyadmin as a database management tool.
Download phpMyadmin:
[root@docker ~] # wget https://files.phpmyadmin.net/phpMyAdmin/4.9.1/phpMyAdmin-4.9.1-all-languages.zip[root@docker ~] # unzip phpMyAdmin-4.9.1-all-languages.zip [root@docker ~] # mv phpMyAdmin-4.9.1-all-languages / wwwroot/html/phpmyadmin// move it to the root directory of the web page and rename it [root@docker ~] # vim / data/nginx/conf.d/default.conf... / / omit part of the content and add the following content location / phpmyadmin {root / usr/share/nginx/html; index index.html index.htm index.php;} location ~ / phpmyadmin/ (? (. *)\. (php | php5)? $) {root / usr/share/nginx/html; fastcgi_pass 200.0.0.30 usr/share/nginx/html; index index.html index.htm index.php; 9000 Fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params;} [root@docker ~] # docker restart nginx / / restart the nginx container [root@docker ~] # docker ps | grep nginx ensures that the nginx container is running properly e000ccd5c883 nginx:latest "nginx-g 'daemon of …" About an hour ago Up 9 seconds 0.0.0.0 80/tcp nginx 80->
Access Test:
The reason for the error is that "--with-mysql..." needs to be added when compiling and installing PHP normally. Looking at this page, it is obvious that the PHP container we are running does not add options for the database.
(8) solve the problem that PHP container does not support associated Mysql database
Log in to the Docker official website, as shown in the figure:
Now that you have seen the answer on Docker's official website, write Dockerfile based on the original php image and generate a new image to support this feature!
[root@docker] # vim DockerfileFROM php:7.2-fpmRUN apt-get update & & apt-get install-y\ libfreetype6-dev\ libjpeg62-turbo-dev\ libpng-dev\ & & docker-php-ext-install-j$ (nproc) iconv\ & & docker-php-ext-configure gd-- with-freetype-dir=/usr/include/-- with-jpeg-dir=/usr/include/\ & & docker-php- Ext-install-j$ (nproc) gd\ & & docker-php-ext-install mysqli pdo pdo_mysql / / add this line To enable it to support the function of connecting to mysql [root@docker ~] # docker build-t phpmysql. / / generate a new image according to the Dockerfile file [root@docker ~] # docker rm phpfpm-f phpmysql// / delete the original phpfpm container [root@docker ~] # docker run-itd-- name phpfpm-p 90009000 name phpfpm-v / wwwroot/html:/usr/share/nginx/html-- network lnmp-- ip 200.0.0.30 phpmysql// or the command to create the phpfpm container Just replace the image with the one you just made: [root@docker ~] # cd / wwwroot/html/phpmyadmin/ [root@docker phpmyadmin] # mv config.sample.inc.php config.inc.php [root@docker phpmyadmin] # vim config.inc.php / / write the configuration file of php 31$ cfg ['Servers'] [$I] [' host'] = '200.0.0.20' / / change the IP address of the mysql container [root@docker ~] # docker restart phpfpm / / restart the php container [root@docker ~] # docker ps | grep phpfpm / / make sure the php container is running properly 367e73bc70bd phpmysql "docker-php-entrypoi …" 6 minutes ago Up 10 seconds 0.0.0.0 9000/tcp phpfpm 9000-> 9000/tcp phpfpm
Access Test:
This is the end of this blog post. Thank you for reading-
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.