LoginSignup
110
60

More than 5 years have passed since last update.

docker-compose upしたときに「A server is already running.」って言われないようにする

Posted at

docker-compose upしてrailsサーバを立ち上げるときにこんなかんじで怒られることがある。

$ docker-compose up
...
web_1           | A server is already running. Check /app/tmp/pids/server.pid.
web_1           | => Booting WEBrick
web_1           | => Rails 5.0.6 application starting in development on http://0.0.0.0:3000
web_1           | => Run `rails server -h` for more startup options
web_1           | Exiting
...

docker-compose killとかでコンテナ終了させたとき、pidファイルが残っているのが原因。

毎回 rm tmp/pids/server.pid するのも手間なので、docker-composeを修正します。

before

version: '3'
services:
  db:
    ...
  web:
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
      - .:/app
    ports:
      - "3000:3000"
    depends_on:
      - db

after

version: '3'
services:
  db:
    ...
  web:
    build: .
    command: /bin/sh -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - .:/app
    ports:
      - "3000:3000"
    depends_on:
      - db

おしまい :wave:

参考

110
60
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
110
60