version: '3'
services:
wad_redis:
image: redis:latest
ports: ###将端口映射到宿主
- "6379:6379"
restart: always
networks: ####使用已创建的网络bridge_internet,并指定IP
bridge_internet:
ipv4_address: 172.18.0.11
networks: ###此处要先声明已有的网络bridge_internet
bridge_internet:
external: true
指定使用默认网络:
#前面无需指定networks,使用已存在的网络watchad-master_default
networks:
default:
external:
name: watchad-master_default
默认桥接网络上的容器间使用容器名称无法ping通,自定义的桥接网络上的容器间的 容器名称(container_name) 可以ping通,hostname不能ping通
使用host网络:
watchad_logstash: image: logstash:6.4.1 ports: - "5044:5044" environment: XPACK_MONITORING_ENABLED: "false" pipeline.batch.size: 10 volumes: - ./settings/logstash/:/usr/share/logstash/pipeline/ network_mode: "host" restart: always
volumes用法:
ersion: '3'
services:
test_alpine01:
image: alpine:latest
container_name: alpine10
volumes:
- type: volume #使用docker管理的volume
source: mydata01
target: /data01
volume:
nocopy: true
- type: bind #将宿主绝对路径映射到容器内部
source: ./curr_mydata02
target: /data02
networks:
- bridge_internet
test_alpine02:
image: alpine:latest
container_name: alpine11
volumes:
- "alpine_v02:/my_v02"
- "/home/d03/index.htm:/var/my/index.htm"
networks:
- bridge_internet
networks:
bridge_internet:
external: true
volumes:
mydata01:
alpine_v02: #不需要已存在,docker会自动创建
volumes_from用法:
volumes_from:
- service_name
- service_name:ro
- container:container_name
- container:container_name:rw
参考:https://www.jianshu.com/p/2217cfed29d7
build用法:
version: '2'
services:
frontend:
build: ./frontend ####指定Dockerfile所在目录
ports:
- "80:80"
server:
build: ./server ####指定Dockerfile所在目录
ports: - "5000:5000" network_mode: "host"
entrypoint.sh文件位置:/usr/local/bin/docker-entrypoint.sh