sudo apt-get update
sudo apt-get remove docker.io containerd runc
sudo apt-get install ca-certificates curl gnupg lsb-release
sudo mkdir -p /etc/apt/keyrings
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
,docker compose
sudo apt-get update
sudo apt-get install docker-compose-plugin
# 查看安装:
sudo docker compose version
mkdir /data
cd /data
mkdir -p mysql/conf.d
mkdir -p mysql/data
mkdir -p nginx/conf.d
mkdir -p nginx/log
mkdir -p php/conf.d
mkdir www
sudo docker run --name nginx -d nginx
#复制出来配置文件:
sudo docker cp nginx:/etc/nginx/conf.d/default.conf nginx/conf.d/
leon@VM-0-6-ubuntu:/data$ cat php/Dockerfile
FROM php:7.4-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libvpx-dev libwebp-dev \
&& docker-php-ext-configure gd --with-webp=/usr/include/webp --with-jpeg=/usr/include --with-freetype=/usr/include/freetype2 \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install mysqli \
&& docker-php-ext-install pdo_mysql
docker build -t myphp:1.0 ./
sudo docker run --name php -d myphp:1.0
sudo docker cp php:/usr/local/etc/php/php.ini-production php/conf.d/php.ini
leon@VM-0-6-ubuntu:/data$ cat nginx/conf.d/default.conf
server {
listen 80;
listen [::]:80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.php 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: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 /usr/share/nginx/html;
fastcgi_pass compose-php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $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;
#}
}
nginx的default.conf 里面
docker run --name mysql --rm mysql:5.7
docker cp mysql:/etc/mysql/conf.d mysql/conf.d
leon@VM-0-6-ubuntu:/data$ tree /data
/data
├── docker-compose.yaml
├── mysql
│ ├── conf.d
│ │ ├── docker.cnf
│ │ ├── mysql.cnf
│ │ └── mysqldump.cnf
│ └── data
├── nginx
│ ├── conf.d
│ │ └── default.conf
│ └── log
│ ├── access.log
│ └── error.log
├── php
│ ├── Dockerfile
│ └── conf.d
│ └── php.ini
└── www
└── info.php
version: "3"
services:
nginx:
image: nginx:latest
container_name: "compose-nginx"
restart: always
ports:
- "80:80"
- "443:443"
environment:
- TZ=Asia/Shanghai
depends_on:
- "php"
volumes:
- "/data/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf"
- "/data/nginx/log:/var/log/nginx"
- "/data/www:/usr/share/nginx/html"
networks:
- net-app
php:
image: myphp:1.0
container_name: "compose-php"
restart: always
environment:
- TZ=Asia/Shanghai
volumes:
- "/data/www:/usr/share/nginx/html"
- "/data/php/conf.d/php.ini:/usr/local/etc/php/php.ini"
networks:
- net-app
mysql:
image: mysql:5.7
container_name: "compose-mysql"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: admin
MYSQL_PASSWORD: admin
volumes:
- ./mysql/data:/var/lib/mysql
- ./mysql/conf.d:/etc/mysql/conf.d
networks:
- net-app
networks:
net-app:
到/data目录下,(有docker-compose.yaml文件的目录下),执行
#启动
docker compose up -d
#停止
docker compose stop
#卸载
docker compose down
echo ''> www/info.php
curl http://localhost/info.php
或浏览器打开访问
连接数据库:
sudo docker run -it --network data_net-app mysql:5.7 mysql -uroot -proot -hcompose-mysql