はじめに
後輩さんが「docker-compose runできない」とのことで見に行ってみたら、なんか変なログが出ていて、ちょっとハマりました。
ネット上にこの情報が見当たらなかったので、記事にしておきます。
全角スペースは、日本特有ですもんね…(苦笑
docker-compose runができない?
$ docker-compose run --rm my_service
とコマンドを打って実行してみるも、下記のログが出力がされる。
$ docker-compose run --rm my_service
Run a one-off command on a service.
For example:
$ docker-compose run web python manage.py shell
By default, linked services will be started, unless they are already
running. If you do not want to start linked services, use
`docker-compose run --no-deps SERVICE COMMAND [ARGS...]`.
Usage:
run [options] [-v VOLUME...] [-p PORT...] [-e KEY=VAL...] [-l KEY=VALUE...] [--]
SERVICE [COMMAND] [ARGS...]
Options:
-d, --detach Detached mode: Run container in the background, print
new container name.
--name NAME Assign a name to the container
--entrypoint CMD Override the entrypoint of the image.
-e KEY=VAL Set an environment variable (can be used multiple times)
-l, --label KEY=VAL Add or override a label (can be used multiple times)
-u, --user="" Run as specified username or uid
--no-deps Don't start linked services.
--rm Remove container after run. Ignored in detached mode.
-p, --publish=[] Publish a container's port(s) to the host
--service-ports Run command with the service's ports enabled and mapped
to the host.
--use-aliases Use the service's network aliases in the network(s) the
container connects to.
-v, --volume=[] Bind mount a volume (default [])
-T Disable pseudo-tty allocation. By default `docker-compose run`
allocates a TTY.
-w, --workdir="" Working directory inside the container
エラーやワーニングではなく、ただコマンドについての説明のような様子。
原因
タイトルの通り、全角スペースが紛れ込んでいました。
上のコマンドでも全角スペースが仕込まれていますので、よく見てみて下さい。
もはや罠です(笑)
なぜこんな初歩的なミスでハマったのか
調べてみるも情報が見当たらない
出力ログの一部でググってみるも、的はずれな記事ばかりヒットします。
そりゃ、runコマンドについての説明ログなので、無理もないですね。
また、docker-compose run できない
とかで調べてみるも、全角スペースに関する記事は見当たりませんでした。
そもそも、初歩的過ぎたのかもしれません。
発見が遅れるターミナル
この件は、後輩さんの環境で起こったのですが、ターミナルのウインドウが小さい状態でした。
そのため、今回のコマンドも改行されていて、全角スペースに気がつけなかったと考えられます。
短いコマンドはなるべく1行で読むようにしたいですね。
さらに、コマンドの再実行の際、ターミナルで↑
を入力していたため、毎回同じコマンドで実行していました。
dockerの問題と思い込んでしまい、コマンド自体に問題があるとは考えられなかったところが、敗因だと思われます。
さいごに
今回の記事は以上です。
教訓としては、
当たり前だと思っていることを疑え
コマンドはなるべく1行にして確認するクセをつけておく
と言ったところでしょうか。
最後までありがとうございました。