参考:win10下载、安装Docker
{
"registry-mirrors": ["https://xxxxxxxxx.mirror.aliyuncs.com"],
"insecure-registries": [],
"debug": false,
"experimental": true,
"features": {
"buildkit": true
}
}
$ docker pull php:7.3.25-fpm-buster
$ docker pull nginx
$ docker pull mysql:5.7
需要其他版本的镜像可以到hub.docker.com,搜索php并通过tags找到自己想要的版本,如果不用管版本直接
docker pull php
即可。
.\mysql\config mysql配置目录
.\mysql\logs mysql日志目录
.\mysql\lib mysql数据目录
.\php php配置目录
.\nginx/www 项目根目录
.\nginx/conf 虚拟域名配置目录
.\nginx/logs nginx访问日志目录
.\nginx/nginx.conf nginx配置文件
version: "3"
services:
mysql:
hostname: mysql
restart: always
image: mysql:5.7
container_name: mysql
ports:
- "3306:3306"
volumes:
- .\mysql\config:/etc/mysql
- .\mysql\log:/var/log/mysql
- .\mysql\lib:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_USER: user
MYSQL_PASSWORD: user123
php:
image: php:7.3.25-fpm-buster
hostname: php
restart: always
container_name: php
build:
context: ./php
dockerfile: Dockerfile
ports:
- "9000:9000"
links:
- mysql:mysql
volumes:
- .\nginx/www:/var/www/html
- .\php\php.ini:/usr/local/etc/php/php.ini
nginx:
hostname: nginx
restart: always
container_name: nginx
image: nginx
ports:
- "80:80"
- "443:443"
links:
- "php:php"
volumes:
- .\nginx/www:/usr/share/nginx/html
- .\nginx/conf:/etc/nginx/conf.d
- .\nginx/logs:/var/log/nginx
- .\nginx/nginx.conf:/etc/nginx/nginx.conf
.\nginx/nginx.conf
)user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
.\nginx/conf
)
server {
listen 80;
server_name localhost;
index index.php index.html error/index.html;
location / {
root /usr/share/nginx/html/;
index index.php index.html index.htm ;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html/xm/public;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}1
注意:
fastcgi_pass php:9000;
php必须填写php的镜像名称
docker-compose up -d
mysql
例:DB_HOST=mysql
Dockerfile
)FROM php:7.3.25-fpm-buster
RUN docker-php-ext-install pdo_mysql
找到;extension=pdo_mysql 去掉;
extension=pdo_mysql
nginx:v1
(镜像名称:镜像标签)。.
代表本次执行的上下文路径,docker build -t nginx:v1 .
docker ps -a
version: "3"
services:
mysql:
hostname: mysql
restart: always
image: mysql:5.7
container_name: mysql
ports:
- "3306:3306"
volumes:
- .\mysql\config:/etc/mysql
- .\mysql\log:/var/log/mysql
- .\mysql\lib:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_USER: user
MYSQL_PASSWORD: user123
php:
image: php:v1
hostname: php
restart: always
container_name: php
build:
context: ./php
dockerfile: Dockerfile
ports:
- "9000:9000"
links:
- mysql:mysql
volumes:
- .\nginx/www:/var/www/html
- .\php\php.ini:/usr/local/etc/php/php.ini
nginx:
hostname: nginx
restart: always
container_name: nginx
image: nginx
ports:
- "80:80"
- "443:443"
links:
- "php:php"
volumes:
- .\nginx/www:/usr/share/nginx/html
- .\nginx/conf:/etc/nginx/conf.d
- .\nginx/logs:/var/log/nginx
- .\nginx/nginx.conf:/etc/nginx/nginx.conf
docker-compose down
docker-compose up -d
docker-compose up -d
up
命令所启动的容器,并移除网络docker-compose down
docker-compose start nginx
docker-compose stop nginx
docker-compose restart nginx
docker exec -it nginx bash
docker build -t nginx:v1 .