10
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

docker-compose upをしてもプロセスが終了してしまうことへの対応

Posted at

基本的には docker はフォアグラウンドでプロセスが走っていれば docker container のプロセスが終了することは無いと思っていたのですが、うまくいかないことがあったのでその対応を書き残しておきます。

tty: true にする

docker-compose.yml
version: '3'
services:
  bot:
    image: watashino/image
    tty: true # make container stay launched
    volumes:
      - ../:/src
    build:
      context: ..
      dockerfile: ./docker/services/bot/Dockerfile

ttyの説明はこちらが詳しいです

でも tty: true を付けているのに、commandを実行するとコンテナが終わってしまう。

bashを対話モードで起動させておく

Dockerfile
CMD bash -c "npm start && /bin/bash"

これによって、プロセスが起動状態のままになりました。

$ docker ps
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS               NAMES
3ae0sguc0f2c        watashino/image              "/bin/sh -c 'bash -c…"   28 minutes ago      Up 28 minutes                           bot
10
6
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
10
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?