我想仅使用 docker-compose.yml 以交互模式输入一个带有逗号的 docker 容器 /bin/bash 。这里有一个关于堆栈溢出的类似问题:Interactive shell using Docker Compose Answers provided there didn't work。这就是我的 docker-compose.yml 的样子:
version: "3"
services:
server:
image: golang:1.11.1
volumes:
- './server:/go'
ports:
- '8080:8080'
command: '-ti'
entrypoint:
- '/bin/bash'
这是我的控制台输入和输出:
[bluebrown@firefly gowild]$ docker-compose up --build
Recreating gowild_server_1 ... done
Attaching to gowild_server_1
server_1 | bash: cannot set terminal process group (-1): Inappropriate ioctl for device
server_1 | bash: no job control in this shell
server_1 | root@d5884893075a:/go# exit
gowild_server_1 exited with code 0
阅读上述帖子,我当然也尝试过替换:
command: '-ti'
对于这两行:
stdin_open: true
tty: true
但是在执行此操作时,docker compose 在附加时会卡住:
[bluebrown@firefly gowild]$ docker-compose up --build
Recreating gowild_server_1 ... done
Attaching to gowild_server_1
没有任何事情发生。没有错误和退出,也没有“完成”消息。
当尝试它sh
而不是bash
它时,它会说以下内容command: '-it
:
server_1 | /bin/sh: 0: Illegal option -t
并且在替换它时也会像 bash 一样卡住。
请注意,我可以在没有命令和入口点的情况下构建和运行服务器,只需使用以下命令:
docker-compose up
docker-compose run --service-ports server
我的问题仍然是如何使用 docker-compose 和入口点来完成它,所以它只能用它来完成docker-compose up
。
更新:我正在使用 Linux manjaro