- Ubuntu : 22.04
- Nginx : 1.18
- PHP : 7.4
-
拉取 Ubuntu 镜像 (默认是最新):
docker pull ubuntu
或者
docker pull ubuntu:latest(版本号)
-
查看本地镜像:
docker images
-
运行容器,并进入容器:
docker run -it -p 8081:80 --name=ubnxphp ubuntu(镜像ID)
退出容器:
exit
查看所有容器:
docker ps -a
启动一个已停止的容器:
docker start b750bbbcfd88 (镜像ID)
进入容器:
docker attach b750bbbcfd88 (镜像ID)
或者
docker exec -it b750bbbcfd88 /bin/bash
-
更新-apt (安装软件前请更新 apt-源,可能会出现找不到安装包)
apt-get update
-
安装 Nginx
apt install -y nginx
nginx-命令
# 关闭 service nginx stop # 开启 service nginx start # 状态 service nginx status # 重启 service nginx restart
-
安装 PHP
apt-get install -y software-properties-common add-apt-repository ppa:ondrej/php # 出现暂停,按回车键[ENTER] apt-get update apt-get install -y php7.4-fpm
php7.4-fpm-命令
# 关闭 service php7.4-fpm stop # 开启 service php7.4-fpm start # 状态 service php7.4-fpm status # 重启 service php7.4-fpm restart
-
安装编译工具
apt install -y vim
-
修改 nginx 配置文件
vi /etc/nginx/sites-available/default
-
启动服务
# 检查 nginx 配置文件 nginx -t # 重启 nginx service nginx restart # 启动 php7.4-fpm service php7.4-fpm start
-
查看服务
# 查看当前进程 ps -aux # 查看 nginx 状态 service nginx status # 查看 php7.4-fpm 状态 service php7.4-fpm status
-
在本地浏览器测试-nginx
-
执行-php
vi /var/www/html/phpinfo.php
<?php phpinfo();
-
生成新的镜像
docker commit -m="ubuntu+nginx+php" -a="ybaog" 74804c6cfdca ubnxphp:v1
大家在使用的过程中可以先跑通nginx后在弄php。
在常规使用中可以根据自己的需求安装PHP其他的拓展。