In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is to share with you about how docker builds a php+nginx+swoole+mysql+redis environment. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Software: docker-ce version 18.09.3, docker-compose version 1.23.2
one。 Create docker image with swoole-redis-pdo_mysql-gd extension
1. Create a dockerfile file
Vim dockerfile
two。 Write in dockerfile file
From php:7.1-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-configure pdo_mysql\ & & docker-php-ext-install pdo_mysql\ & & pecl install redis-4.3.0\ & & pecl install swoole\ & & docker-php-ext-enable redis swoole
3. To create a custom php image, don't leave out the last'.', which is to specify the current directory to build the image.
Docker build-t myphp4.
Run instructions, due to network problems, etc., need to wait a long time, after success, there will be code similar to the following
...
Build process completed successfully
Installing'/ usr/local/include/php/ext/swoole/config.h'
Installing'/ usr/local/lib/php/extensions/no-debug-non-zts-20160303/swoole.so'
Install ok: channel://pecl.php.net/swoole-4.3.1
Configuration option "php_ini" is not set to php.ini location
You should add "extension=swoole.so" to php.ini
Removing intermediate container ad1420f7554f
-- > 2f2f332d73ce
Successfully built 2f2f332d73ce
Successfully tagged myphp4:latest
So far, the custom myphp4 image of docker has been created successfully!
two。 Create a docker-compose.yml file
Mkdir pnsmrcd pnsmrvim docker-compose.yml
Write the following code
Version: '3.0'services:nginx: image: "nginx:latest" ports:-"10000 nginx:latest 80" volumes:-/ var/www/html:/usr/share/nginx/htmlphp-fpm: image: "myphp4" volumes:-/ var/www/html:/usr/share/nginx/htmlmysql: image: "mysql:latest" redis: image: "redis:4.0"
Running instruction
Docker-compose up-d
Success can be seen.
WARNING: The Docker Engine you're using is running in swarm mode.
Compose does not use swarm mode to deploy services to multiple nodes in a swarm. All containers will be scheduled on the current node.
To deploy your application across the swarm, use `docker stack deploy`.
Creating network "pnsmr_default" with the default driver
Creating pnsmr_php-fpm_1... Done
Creating pnsmr_redis_1... Done
Creating pnsmr_mysql_1... Done
Creating pnsmr_nginx_1... Done
At this point, the nginx mysql redis php service has been enabled
three。 Modify each service profile
1. You should enter your server ip address here, as shown in the following figure
two。 Next, to modify the configuration file of nginx in the container, use the instruction to check the docker IP address of each container.
Docker inspect-f'{{.Name}}-{{range .NetworkSettings.Networks}} {{.IPAddress}} {{end}}'$(docker ps-aq)
This instruction can check the ip of all containers opened with docker-compose. The result is similar to the figure below, and you can use the corresponding ip address for internal communication.
3. Copy the configuration file of the nginx container and modify and replace it so that nginx can parse php
Docker cp pnsmr_nginx_1:/etc/nginx/conf.d/default.conf nginx.confvim nginx.conf
Change to the following code
Server {listen 80; server_name localhost; # charset koi8-r; # access_log / var/log/nginx/host.access.log main; location / {root / usr/share/nginx/html; index index.html index.htm;} # error_page 404 / 404.html; # redirect server error pages to the static page / 50x.html # error_page 500 502 503 504 / 50x.html Location = / 50x.html {root / usr/share/nginx/html;} # proxy the PHP scripts to Apache listening on 127.0.0.1 proxy the PHP scripts to Apache listening on 80 # # location ~. Php$ {# proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1 location ~. Php$ {root html; fastcgi_pass 172.24.0.39000 # here you need to fill in the docker internal communication of your php container ip fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME / usr/share/nginx/html/$fastcgi_script_name; include fastcgi_params;} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # # location ~ /\ .ht {# deny all #}} docker cp nginx.conf pnsmr_nginx_1:/etc/nginx/conf.d/default.conf # copy the modified configuration file to the container docker container stop pnsmr_nginx_1 docker container start pnsmr_nginx_1 # restart the nginx container to make the configuration file effective vim / var/www/html/index.php # create a new index.php file in the local directory of the server, enter
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.