提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
最近各种开发、测试、生产环境都从传统的一键LNMP(https://oneinstack.com/)升级Docker,不到10台服务器,每台服务器docker pull…Container A,B…实在太繁杂,尤其是默认的自动获取IP,特别麻烦每次部署都不一样。知道使用docker-compose编排,可以有效解决这个问题,但是一直没得空,周末抽空写了一个,刚好可以在一台新的数据仓库服务器部署。本docker-compose.yml主要解决如下几个问题:
提示:以下是本篇文章正文内容,下面案例可供参考
Docker-Compose项目是Docker官方的开源项目,负责实现对Docker容器集群的快速编排。
代码如下:
version: '3.8'
services:
nginx:
image: nginx:1.19.2
container_name: ${COMMON_DEPLOY_ENV}-nginx
volumes:
- /etc/localtime:/etc/localtime:ro
- ${COMMON_VOLUMENS_PATH}/nginx/html:/usr/share/nginx/html:ro
restart: always
ports:
- "21601:80"
environment:
- NGINX_PORT=80
networks:
sly_net_pro:
ipv4_address: 172.172.0.2
mysql:
image: mysql:5.7.30
container_name: ${COMMON_DEPLOY_ENV}-mysql
volumes:
- /etc/localtime:/etc/localtime:ro
- ${COMMON_VOLUMENS_PATH}/mysql:/var/lib/mysql
restart: always
ports:
- "21602:3306"
environment:
MYSQL_ROOT_PASSWORD: Admin2020
MYSQL_DATABASE: db_manage
MYSQL_USER: dev_user
MYSQL_PASSWORD: dev_user
networks:
sly_net_pro:
ipv4_address: 172.172.0.3
tomcat:
image: tomcat:8.5.54-jdk8
container_name: ${COMMON_DEPLOY_ENV}-tomcat
volumes:
- /etc/localtime:/etc/localtime:ro
- ${COMMON_VOLUMENS_PATH}/tomcat/webapps:/usr/local/tomcat/webapps
environment:
TZ: Asia/Shanghai
restart: always
ports:
- "21603:8080"
networks:
sly_net_pro:
ipv4_address: 172.172.0.4
redis:
image: redis:5.0.9-buster
container_name: ${COMMON_DEPLOY_ENV}-redis
volumes:
- /etc/localtime:/etc/localtime:ro
- ${COMMON_VOLUMENS_PATH}/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf
restart: always
ports:
- "21604:6379"
networks:
sly_net_pro:
ipv4_address: 172.172.0.5
memecached:
image: memcached:1.6.7
container_name: ${COMMON_DEPLOY_ENV}-memcached
volumes:
- /etc/localtime:/etc/localtime:ro
restart: always
ports:
- "21605:11211"
networks:
sly_net_pro:
ipv4_address: 172.172.0.6
mongo:
image: mongo:4.4.1
container_name: ${COMMON_DEPLOY_ENV}-mongo
volumes:
- /etc/localtime:/etc/localtime:ro
- ${COMMON_VOLUMENS_PATH}/mongo:/etc/mongo
restart: always
ports:
- "21606:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: Admin2020
networks:
sly_net_pro:
ipv4_address: 172.172.0.7
clickhouse:
image: yandex/clickhouse-server:20.6.6.7
container_name: ${COMMON_DEPLOY_ENV}-clickhouse
volumes:
- /etc/localtime:/etc/localtime:ro
- ${COMMON_VOLUMENS_PATH}/clickhouse-server:/var/lib/clickhouse yandex/clickhouse-server
restart: always
ports:
- "21607:8123"
networks:
sly_net_pro:
ipv4_address: 172.172.0.8
networks:
sly_net_pro:
ipam:
driver: default
config:
- subnet: "172.172.0.0/24"
在同级目录下,创建.env文件,可直接调用变量,代码如下:
# define env var default value.
COMMON_VOLUMENS_PATH=/data/docker-data
COMMON_DEPLOY_ENV=pro