我试图限制docker的日志文件的最大大小。每个容器的日志文件最大值应为100M。因此,每个容器(例如edge
,worker
等)应仅允许具有100MB的日志文件。
我试图插入:
log_opt:
max-size: 100m
在我的docker-compose.yml文件的末尾但是我收到了一个错误。 我应该把它放在哪里?此外,当我将它放在每个容器定义中时,我收到一个错误。我阅读了docker文档,但没有说明确切地放置选项的位置。
这是我的docker-compose.yml
文件:
version: '2.0'
services:
ubuntu:
image: ubuntu
volumes:
- box:/box
cache:
image: redis:3.0
rabbitmq:
image: rabbitmq:3-management
volumes:
- ${DATA}/rabbitmq:/var/lib/rabbitmq
ports:
- "15672:15672"
- "5672:5672"
placements-store:
image: redis:3.0
command: redis-server ${REDIS_OPTIONS}
ports:
- "6379:6379"
api:
image: ruby:2.3
command: bundle exec puma -C config/puma.rb
env_file:
- ./.env
working_dir: /app
volumes:
- .:/app/
- box:/box
expose:
- 3000
depends_on:
- cache
- placements-store
worker:
image: ruby:2.3
command: bundle exec sidekiq -C ./config/schedule.yml -q default -q high_priority,5 -c 10
env_file:
- ./.env
working_dir: /app
environment:
INSTANCE_TYPE: worker
volumes:
- .:/app/
- box:/box
depends_on:
- cache
- placements-store
sidekiq-monitor:
image: ruby:2.3
command: bundle exec thin start -R sidekiq.ru -p 9494
env_file:
- ./.env
working_dir: /app
volumes:
- .:/app/
- box:/box
depends_on:
- cache
expose:
- 9494
sneakers:
image: ruby:2.3
command: bundle exec rails sneakers:run
env_file:
- ./.env
working_dir: /app
environment:
INSTANCE_TYPE: worker
volumes:
- .:/app/
- box:/box
depends_on:
- cache
- placements-store
- rabbitmq
edge:
image: ruby:2.3
command: bundle exec thin start -R config.ru -p 3000
environment:
REDIS_URL: redis://placements-store
RACK_ENV: development
BUNDLE_PATH: /box
RABBITMQ_HOST: rabbitmq
working_dir: /app
volumes:
- ./edge:/app/
- box:/box
depends_on:
- placements-store
- rabbitmq
expose:
- 3000
proxy:
image: openresty/openresty:latest-xenial
ports:
- "80:80"
- "443:443"
volumes:
- ./config/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf
volumes:
box:
# node_modules:
# bower_components:
# client_dist:
这是我尝试过的,例如在rabbitmq
容器下插入:
version: '2.0'
services:
ubuntu:
image: ubuntu
volumes:
- box:/box
cache:
image: redis:3.0
rabbitmq:
image: rabbitmq:3-management
#volumes:
# - ${DATA}/rabbitmq:/var/lib/rabbitmq
ports:
- "15672:15672"
- "5672:5672"
log_opt:
max-size: 50m
placements-store:
image: redis:3.0
command: redis-server ${REDIS_OPTIONS}
ports:
- "6379:6379"
这是我得到的错误:
错误:撰写文件'./docker-compose.yml'无效,因为: services.rabbitmq:'log_opt'
的配置选项不受支持
尝试使用log_opt:
更改options:
并收到同样的错误:
错误:撰写文件'./docker-compose.yml'无效,因为: services.rabbitmq:'options'
的配置选项不受支持
码头版也是:
docker --version && docker-compose --version
Docker version 1.11.2, build b9f10c9/1.11.2
docker-compose version 1.9.0, build 2585387
更新:
尝试使用logging
选项,如文档所述(对于版本2.0):
version: '2.0'
services:
ubuntu:
image: ubuntu
volumes:
- box:/box
cache:
image: redis:3.0
rabbitmq:
image: rabbitmq:3-management
#volumes:
# - ${DATA}/rabbitmq:/var/lib/rabbitmq
ports:
- "15672:15672"
- "5672:5672"
logging:
driver: "json-file"
options:
max-size: 100m
max-file: 1
placements-store:
image: redis:3.0
command: redis-server ${REDIS_OPTIONS}
ports:
- "6379:6379"
获取错误:
错误:对于rabbitmq无法为服务rabbitmq创建容器: json:无法将数字解组为字符串ERROR的Go值: 在启动项目时遇到错误。