赞
踩
1、image
指定镜像
image: ubuntu:14.04
2、buildc
指定Dockerfile的路径创建镜像,compose基于这个镜像启动服务容器
build: /path/to/build/dir
3、command
替换当前镜像默认启动的命令
command: bundle exec thin -p 3000
# ==
command: [bundle,exec,thin,-p,3000]
4、container_name:<项目名称><服务名称><序号> (容器名)
container_name: app (自定义项目名字)
5、depends_on
定义依赖关联
version: '2'
services:
web:
build: .
depends_on:
1 - db
- redis
redis:
image: redis
db:
image: postgres
6、dns
dns: 8.8.8.8
dns:
- 8.8.8.8
- 9.9.9.9
7、tmpfs
定义临时目录,容器关闭后会被删除
tmpfs: /run
tmpfs:
- /run
- /tmp
8、 entrypoint
替换容器启动默认命令
entrypoint: /code/entrypoint.sh
9、env_file
定义当前环境变量的文件,格式必须是key=value(需要调用文件)
env_file: .env
env_file:
- ./common.env
- ./apps/web.env
- /opt/secrets.env
10、environment:镜像变量,(可以直接定义)
environment:
RACK_ENV: development
SHOW: 'true'
SESSION_SECRET:
environment:
- RACK_ENV=development
- SHOW=true
- SESSION_SECRET
11、expose
定义比较重要的端口,不代表外界可以访问该端口,
expose:
- "3000"
- "8000"
12、 external_links:链接外部容器
docker-compose会创建一个新的网桥,使各个项目之间不能通信,但需要读取访
1 问其他项目的一些信息时,则需要使用external_links调用
external_links:
- redis_1
- project_db_1:mysql
- project_db_1:postgresql
13、extra_hosts
添加hosts记录
extra_hosts:
- "somehost:162.242.195.82"
- "otherhost:50.31.209.229"
14、labels - docker-swarm
用于集群化,docker-compose多用于单机部署
labels:
com.example.description: "Accounting webapp"
com.example.department: "Finance"
com.example.label-with-empty-value: ""
labels:
- "com.example.description=Accounting webapp"
- "com.example.department=Finance"
- "com.example.label-with-empty-value"
15、links
与 Docker client 的 --link 一样效果,会连接到其它服务中的容器
links:
- db
- db:database
- redis
16、 logging
默认日志存放位置:/var/ib/docker/container
logging:
driver: syslog
options:
syslog-address: "tcp://192.168.0.42:123"
17、pid
pid: "host"
18、port
ports: - "3000" 物理机的随机端口映射到容器的3000端口
- "8000:8000" 访问物理机的8000,访问到容器的8000
- "49100:22" 访问物理机的8000,访问到容器的8000
- "127.0.0.1:8001:8001" 仅允许通过回环地址访问
19、security_opt
单机部署没有意义
# 为每个容器覆盖默认的标签。简单说来就是管理全部服务的标签。比如设置全
部服务的user标签值为USER。
1 :
- label:user:USER
- label:role:ROLE
20、 stop_signal
信号
stop_signal: SIGUSR1
21、volumes
volumes:
// 只是指定一个路径,Docker 会自动在创建一个数据卷(这个路径是容器内
部的)。
- /var/lib/mysql
// 使用绝对路径挂载数据卷
- /opt/data:/var/lib/mysql
// 以 Compose 配置文件为中心的相对路径作为数据卷挂载到容器。
- ./cache:/tmp/cache
// 使用用户的相对路径(~/ 表示的目录是 /home/<用户目录>/ 或者
/root/)。
- ~/configs:/etc/configs/:ro
// 已经存在的命名的数据卷。
- datavolume:/var/lib/mysql
22、volumes_from:从其它容器或者服务挂载数据卷,可选的参数是 :ro或
者 :rw,前者表示容器只读,后者表示容器对数据卷是可读可写的。默认情况下
是可读可写的
volumes_from:
- service_name
- service_name:ro
- container:container_name
- container:container_name:rw
23、cap_add, cap_drop
添加权限
cap_add:
- ALL
cap_drop:
- NET_ADMIN
- SYS_ADMIN
--cap-add Add Linux capabilities
--cap-drop Drop Linux capabilities
--privileged Give extended privileges to this container(给root权限)
--device=[] Allows you to run devices inside the container without
the --privileged flag.
SYS_MODULE Load and unload kernel modules.
SYS_RAWIO Perform I/O port operations (iopl(2) and ioperm(2)).
SYS_PACCT Use acct(2), switch process accounting on or off.
SYS_ADMIN Perform a range of system administration operations.
SYS_NICE Raise process nice value (nice(2), setpriority(2)) and
change the nice value for arbitrary processes.
SYS_RESOURCE Override resource Limits.
SYS_TIME Set system clock (settimeofday(2), stime(2), adjtimex(2));
set real-time (hardware) clock.
SYS_TTY_CONFIG Use vhangup(2); employ various privileged ioctl(2)
operations on virtual terminals.
AUDIT_CONTROL Enable and disable kernel auditing; change auditing
filter rules; retrieve auditing status and filtering rules.
MAC_ADMIN Allow MAC configuration or state changes. Implemented for
the Smack LSM.
MAC_OVERRIDE Override Mandatory Access Control (MAC). Implemented
for the Smack Linux Security Module (LSM).
NET_ADMIN Perform various network-related operations.
SYSLOG Perform privileged syslog(2) operations.
DAC_READ_SEARCH Bypass file read permission checks and directory
read and execute permission checks.
LINUX_IMMUTABLE Set the FS_APPEND_FL and FS_IMMUTABLE_FL i-node
flags.
NET_BROADCAST Make socket broadcasts, and listen to multicasts.IPC_LOCK Lock memory (mlock(2), mlockall(2), mmap(2), shmctl(2)).IPC_OWNER Bypass permission checks for operations on System V IPCobjects.
SYS_PTRACE Trace arbitrary processes using ptrace(2).SYS_BOOT Use reboot(2) and kexec_load(2), reboot and load a newkernel for later execution.
LEASE Establish leases on arbitrary files (see fcntl(2)).WAKE_ALARM Trigger something that will wake up the system.BLOCK_SUSPEND Employ features that can block system suspend.
24、extends
链接一个子文件,类似于incloud
extends:
file: common.yml
service: webapp
25、network_mode
network_mode: "bridge"
network_mode: "host"
network_mode: "none"
network_mode: "service:[service name]"
network_mode: "container:[container name/id]"
26、 networks
services:
1some-service:
networks:
- some-network
- other-network
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。