1

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:
1

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.