Download image
docker pull nginxdocker pull bitnami/php-fpm
Environment configuration
Build your development environment in the physical organization configuration directory and Nginx configuration files, easy to manage.
Building containers
docker run --name myFpm -v /Users/zhen/www-root/work:/usr/share/nginx/html -v /Users/zhen/docker/lnmp/nginx:/etc/nginx/conf.d -d bitnami/php-fpmdocker run --name myNginx -p 80:80 -v /Users/zhen/www-root/work:/usr/share/nginx/html -v /Users/zhen/docker/lnmp/nginx:/etc/nginx/conf.d -d nginx
Although all normal but still cannot access through the physical machine, view the IP information, found the problem. To modify the Nginx configuration.
docker inspect myFpm | grep "IPAddress"docker inspect myNginx | grep "IPAddress"
server { listen 80; server_name xxxx.com xxxxx.com xxxx.com index index.html index.htm index.php; root /usr/share/nginx/html/mhadmin; #access_log /tmp/mhadmin.log; #error_log /tmp/mhadmin_error.log error; location / { index index.php index.html; try_files $uri $uri/ /index.php?$query_string; if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } } location ~ \.php { fastcgi_pass 172.17.0.2:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; }}修改fastcgi_pass 127.0.0.1:9000; 为:fastcgi_pass 172.17.0.2:9000;
Get.
Common commands
Enter the container
docker exec -it myNginx /bin/bash
To replicate the configuration within the container to the host machine
docker cp myNginx:/etc/nginx/conf.d/default.conf ./default.conf
Copy host machine files to container
docker cp ./default.conf myNginx:/etc/nginx/conf.d/default.conf
Nginx Reload Configuration
service nginx reload
Stop all containers
docker stop $(docker ps -a -q)
Remove all containers
docker rm $(docker ps -a -q)
Docker-nginx + PHP-FPM Development environment