大网数据广告活动
服务器运维问答

Docker-compose stop does not stop all containers

· 52CE 我爱测

I have a test rails 5.2.2 app running in docker and reports no errors in console but when I run docker-compose stop there is 1 container which doesn't stop. My o/s is macos running Docker for Mac. The container which doesn't stop…

问题原文

原帖链接 · markhorrocks · CC BY-SA 4.0

I have a test rails 5.2.2 app running in docker and reports no errors in console but when I run docker-compose stop there is 1 container which doesn't stop. My o/s is macos running Docker for Mac. The container which doesn't stop is db_data.

docker-compose up will restart the stopped container and the app continues to run normally.

Here is my docker-compose file

version: '3'
services:
  postgres:
    image: postgres
    env_file:
    - '.env'
    environment:
    - PGDATA=/var/lib/postgresql/data        
  db_data:
    image: postgres
    volumes:
    - /var/lib/postgresql/data
    command: /bin/true
  redis:
    image: redis
    ports:
    - "6379:6379"
  web:
    build: .
    command: "bin/bundle exec rails s -p 3000 -b 0.0.0.0"
    depends_on:
    - redis
    - postgres
    env_file:
    - '.env'
    environment:
    - RAILS_ENV=development
    - REDIS_URL=redis
    - REDIS_PORT=6379
    volumes:
    - .:/usr/src/app
    - gem_cache:/gems
    ports:
    - "3000:3000"
    environment:
    - WEBPACKER_DEV_SERVER_HOST=webpack_dev_server
  webpack_dev_server:
    build: .
    command: ./bin/webpack-dev-server
    ports:
    - "3035:3035"
    env_file:
    - '.env'
    environment:
    - RAILS_ENV=development
    - REDIS_URL=redis
    - REDIS_PORT=6379
    - WEBPACKER_DEV_SERVER_HOST=0.0.0.0
    volumes:
    - .:/usr/src/app
    - gem_cache:/gems

volumes:
  gem_cache:

已采纳解答

原帖链接 · Drakes · CC BY-SA 4.0

You've probably already figured this out, but your db_data service is running the command /bin/true. If you look at the entrypoint in the Dockerfile it is to a docker-entrypoint.sh. Inside that script is the line if [ "$1" = 'postgres' ]; then ..., so when you pass in /bin/true as the command this block is bypassed (some init script) and the container exits immediately.

You're not seeing the container name when you run docker-compose stop because it probably wasn't running.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-12-26)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。