Docker 安装 Nginx + PHP + MySQL

docker pull nginx
docker run --name doc_nginx -p 8080:80 -d nginx
Test http 8080
docker stop doc_nginx
docker rm doc_nginx

docker pull php:7.4.8-fpm
docker run --name doc_php_74 -v /usr/share/nginx/html:/www -d php:7.4.8-fpm

mkdir /home/li/nginx/conf.d
vi /home/li/nginx/conf.d/php_nginx.conf
Add:
server {
    listen       80;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm index.php;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~ \.php$ {
        fastcgi_pass   doc_php_74:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /www/$fastcgi_script_name;
        include        fastcgi_params;
    }
}

docker run --name doc_nginx -p 8080:80 -d \
    -v /usr/share/nginx/html:/usr/share/nginx/html:ro \
    -v /home/li/nginx/conf.d:/etc/nginx/conf.d:ro \
    --link doc_php_74 \
    nginx

vi /usr/share/nginx/html/info.php
Add:
<?php phpinfo(); ?>

Test http://localhost:8080/info.php

docker ps -a
docker logs -f doc_nginx

Install extensions:
docker exec -i -t doc_php_74 /bin/bash
更换软件源:
mv /etc/apt/sources.list /etc/apt/sources.list.bak
echo "deb http://mirrors.163.com/debian/ buster main" > /etc/apt/sources.list
echo "deb http://mirrors.163.com/debian-security buster/updates main" >> /etc/apt/sources.list
echo "deb http://mirrors.163.com/debian/ buster-updates main" >>/etc/apt/sources.list
apt-get update
apt-get install -y libwebp-dev libjpeg-dev libpng-dev libfreetype6-dev libicu-dev
apt-get install -y libmemcached-dev zlib1g-dev
docker-php-ext-install bcmath gd intl opcache
pecl install memcached redis mongodb xdebug
docker-php-ext-enable bcmath gd intl memcached opcache redis mongodb xdebug

docker restart doc_php_74


docker pull mysql:latest
docker run -itd --name doc_mysql -p 3307:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
mysql -h127.0.0.1 -P3307 -uroot -p


docker login
docker commit -m="install extensions" -a="yannanfei0o" 36cc6a886c7f yannanfei0o/php_7.4.8_with_ext
docker push yannanfei0o/php_7.4.8_with_ext

查看docker对应log的地址:
docker inspect --format='{{.LogPath}}' containername


解决 vi 中文乱码:
vi /etc/virc
在最后加上:
set fileencodings=utf-8,gb2312,gbk,gb18030
set termencoding=utf-8
set encoding=prc