最近感觉docker挺好用的,由于测试服务器经常重装,这里先记录下compose文件,后边重装直接复制就行啦。
由于服务器只针对这一个web服务,这里的network_mode
使用的host
.
docker-compose.yml
version: "3.7"
services:
nginx:
image: nginx:stable-perl
container_name: nginx
restart: always
ports:
- "80:80"
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
network_mode: host
docker-compose.yml
version: "3.7"
services:
redis:
image: redis:6-alpine3.17
container_name: myredis
restart: always
privileged: true
command: redis-server --appendonly yes
network_mode: host
docker-compose.yml
version: "3.7"
services:
mysql:
image: mysql:5.7
container_name: mymysql
restart: always
privileged: true
volumes:
- ./mysql:/var/lib/mysql
- ./update:/data/update
environment:
- "MYSQL_ROOT_PASSWORD=root"
command:
--default-time-zone="+8:00"
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--max_connections=1000
--innodb_lock_wait_timeout=500
network_mode: host
后边根据业务创建数据库,如果确定web只有这一个可以直接通过以下创建:
volumes:
- ./init:/docker-entrypoint-initdb.d/
environment:
- "MYSQL_ROOT_PASSWORD=root"
- "MYSQL_DATABASE=testdb"
- "TZ=Asia/Shanghai"
version: "3.7"
services:
mysql:
image: mysql:5.7
container_name: mysql
restart: always
privileged: true
volumes:
- ./mysql:/var/lib/mysql
- ./mysqlupdate:/data/update
environment:
- "MYSQL_ROOT_PASSWORD=root"
command:
--default-time-zone="+8:00"
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--max_connections=1000
--innodb_lock_wait_timeout=500
redis:
image: redis:6-alpine3.17
container_name: redis
restart: always
privileged: true
expose:
- 6379
command: redis-server --appendonly yes
ftp:
image: fauria/vsftpd:latest
container_name: vsftp
restart: always
ports:
- "21:21"
- "20:20"
- 9900-9999:9900-9999
expose:
- 21
volumes:
- ./ftp:/home/vsftpd/testabc
environment:
- "FTP_USER=testabc"
- "FTP_PASS=123456"
- "FTP_MIN_PORT=9900"
- "FTP_MAX_PORT=9999"
networks:
- server-web
tomcat:
image: tomcat:9.0
container_name: tomcat
restart: always
ports:
- 8080:8080
networks:
- server-web
nginx:
image: nginx:1.9.5
container_name: nginx
restart: always
privileged: true
ports:
- 80:80
- 443:443
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./ftp:/data/ftp
networks:
- server-web
networks:
server-web:
driver: bridge
注意 networks 统一使用一个,这样相互之间可以通信访问。
转载请注明出处: https://chrunlee.cn/article/docker-web-service-yml.html