6
5

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を使った場合のデバッグ方法

Last updated at Posted at 2018-10-21

#目的
docker-composeでDockerコンテナを動かした場合のコンテナ内で動作するコードのデバッグ.PycharmによるRemote Debugは設定が大変そうだったので断念し,pdbを使ったデバッグを試みた.
参照:https://stackoverflow.com/questions/30854967/docker-compose-and-pdb#comment56942332_30901026

#方法
ソースコードにpdbを挿入

/tmp/main.py
import pdb; 

if __name__ == "__main__":
    pdb.set_trace()

ymlファイルにstdin_open: truetty: trueを追加
(docker runにおける-i, -tオプションと効果は同様)

docker-compose.yml
version: '2'
services:
  sample:
    image: "test"
    command: ["python", "/tmp/main.py"]
    stdin_open: true
    tty: true
...

対象コンテナをdocker-compose docker-compose.yml up -dで起動後,docker attach <containerid>で対象のコンテナにattachすると,(pdb)のコンソールが起動してする.

6
5
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
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?