redis:
image: redis
postgres:
image: postgres
server1:
image: testserver # test server镜像
env_file: # 定制test-server-1运行环境
- "server1.env" # REDIS_HOST=redis POSTGRES_HOST=postgres PROFILE=dev
links:
- "redis"
- "postgres"
expose:
- "12345" # test server的监听端口
server2:
image: testserver
env_file:
- "server2.env" # REDIS_HOST=redis POSTGRES_HOST=postgres PROFILE=staging
links:
- "redis"
- "postgres"
expose:
- "123456"
server3:
image: testserver
env_file:
- "server3.env" # REDIS_HOST=redis POSTGRES_HOST=postgres PROFILE=production
links:
- "redis"
- "postgres"
expose:
- "123456"
nginx:
image: nginx
links:
- "server1"
- "server2"
- "server3"
ports:
- "23456" # 为test server1准备的外部端口
- "13456"
- "12456"
volumes: # 为每个test server创建一个virtual host
- "
server1.site:/etc/nginx/sites-enabled/server1" # listen 23456; proxy_pass http://server1:123456;
- "
server2.site:/etc/nginx/sites-enabled/server2" # listen 13456; proxy_pass http://server2:123456;
- "
server3.site:/etc/nginx/sites-enabled/server3" # listen 12456; proxy_pass http://server3:123456;
只是写了手动配置这些环境,
实际上可以写个简单脚本接受开发人员提供的env, site配置自动新增docker container并重启nginx