Docker-compose無法進入Ubuntu的Bash解法

 Docker-compose無法進入Ubuntu的Bash解法

這個問題困擾我2個小時,最後其實也只能workaround

使用bvobart的解法

嘗試使用bvobart回應的方法,改用docker-compose run {service-name}就成功進入bash了

https://github.com/docker/compose/issues/2951

一個簡單Ubuntu的docker-compose.yml如下

version: "3.8"

services:
the-ubuntu:
image: ubuntu:16.04
stdin_open: true
tty: true

build的時候使用
docker-compose build

執行Bash要使用
docker-compose run the-ubuntu

不用要記得關閉
docker-compose down

使用下面這個指令,就會卡在attaching然後進不去Bash
docker-compose up

另一種解法

看其他資料時看到可以在compose內用無限迴圈來不讓它執行結束

version: "3.8"

services:
the-ubuntu:
image: ubuntu:16.04
command: /bin/sh -c "while sleep 1000; do :; done"

這樣也以用run指令來進入bash
docker-compose run the-ubuntu bash

留言