近期帮朋友配置了一下服务器,涉及到docker-compose这里记录一下。
1.docker-compose.yml
version: '3'
services:
nginx:
image: hub.c.163.com/library/nginx:1.13
restart: always
volumes:
#配置文件目录
- ~/tools/nginx/conf.d:/etc/nginx/conf.d
#html目录
- ~/factory/source/web:/etc/nginx/html
ports:
- "80:80"
networks:
- mi_dev
service:
image: 服务镜像
ports:
- "8002:8080"
networks:
- mi_dev
mysql:
image: hub.c.163.com/library/mysql:5.7
volumes:
# 存放容器启动后的一些数据文件
- ~/data/mysql:/var/lib/mysql
# 使用服务器时间,默认的容器的时区是GMT
- /etc/localtime:/etc/localtime:ro
ports:
- "3306:3306"
environment:
MYSQL_USER: root
MYSQL_PASSWORD: 123456
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: mi
restart: unless-stopped
networks:
- mi_dev
# 容器间通信的网络
networks:
mi_dev:
driver: bridge
服务配置数据库连接时就要更换成mysql的容器名(默认与服务名相同)。
2.nginx.conf
upstream service {
server 服务的host:8002;
}
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location ^ ~/api/ {
proxy_pass http: //service;
proxy_set_header Host $host;
proxy_set_header X - Real - IP $remote_addr;
proxy_set_header X - Forwarded - For $proxy_add_x_forwarded_for;
proxy_connect_timeout 1;
proxy_read_timeout 1;
proxy_send_timeout 1;
}
}
nginx的配置主要的就这一部分。
这里就不写Dockerfile的写法啦!
最后感谢诸多博客,没记下地址就不贴了!