docker search nginxdocker pull nginx
docker run -d --name nginx -p 8080:80 -v /tmp:/usr/share/nginx/html docker.io/nginx
说明
在/tmp 目录下新建一个 index.html 里面打个 hello nginx
访问 127.0.0.1:8080 正确的情况下会出现该文件内容
docker search php-fpmdocker pull bitnami/php-fpm
4.运行 php-fpm
docker run -d -v /tmp:/usr/share/nginx/html --name php-fpm docker.io/bitnami/php-fpm
docker inspect php-fpm | grep "IPAddress"
#copy 配置文件docker cp nginx:/etc/nginx/conf.d/default.conf ./default.confvim ./default.conf#copy 下面的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 index.php; } #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:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root html; fastcgi_pass 172.17.0.2:9000; 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; #}}# 修改 fastcgi_pass 127.0.0.1:9000; 为:# fastcgi_pass 172.17.0.2:9000;# 其中 172.17.0.2 是 上面查看 IP 获取的 每次都不一样#覆盖到 nginx docker cp ./default.conf nginx:/etc/nginx/conf.d/default.conf#重启 nginxdocker restart nginx
<?php echo phpinfo();
进入容器
docker exec -it nginx /bin/bash
复制容器内的配置到宿主机器
docker cp nginx:/etc/nginx/conf.d/default.conf ./default.conf
复制宿主机器文件到容器
docker cp ./default.conf myNginx:/etc/nginx/conf.d/default.conf
docker 重启容器
docker restart nginx
停止所有容器
docker stop $(docker ps -a -q)
删除所有容器
docker rm $(docker ps -a -q)