erlang Docker容器在启动后立即关闭

ohfgkhjo  于 2022-12-08  发布在  Erlang
关注(0)|答案(1)|浏览(158)

I want to setup learning development container for VSCode on my Windows 10 machine, but when I press "Open Folder in a Container" in VSCode I get an error:

[2020-11-24T10:21:22.963Z] [PID 8208] 
[2020-11-24T10:21:23.070Z] [PID 8208] [8794 ms] Start: Run: docker ps -q -a --filter label=com.docker.compose.project=lecture2 --filter label=com.docker.compose.service=development
[2020-11-24T10:21:23.762Z] [PID 8208] [9486 ms] Start: Run: docker inspect --type container 03d485c0d0b0
[2020-11-24T10:21:24.630Z] [PID 8208] [10354 ms] Start: Inspecting container
[2020-11-24T10:21:24.631Z] [PID 8208] [10355 ms] Start: Run: docker inspect --type container 03d485c0d0b08ae5af7bc81124f9205d933ce77441829cfcf176a6dd767ab291
[2020-11-24T10:21:25.656Z] [PID 8208] [11380 ms] Start: Run: docker exec -i -u root -e VSCODE_REMOTE_CONTAINERS_SESSION=663b838f-c06e-4178-ae10-5f48efb218811606213272822 03d485c0d0b08ae5af7bc81124f9205d933ce77441829cfcf176a6dd767ab291 /bin/sh
[2020-11-24T10:21:25.678Z] [PID 8208] [11402 ms] Start: Run in container: uname -m
[2020-11-24T10:21:26.558Z] [PID 8208] [12282 ms] Start: Run in container: cat /etc/passwd
[2020-11-24T10:21:26.558Z] [PID 8208] [12282 ms] Stdin closed!
[2020-11-24T10:21:26.570Z] [PID 8208] [12294 ms] Shell server terminated (code: 1, signal: null)

Error response from daemon: Container 03d485c0d0b08ae5af7bc81124f9205d933ce77441829cfcf176a6dd767ab291 is not running

And if I just issue command:

docker-compose up

The container is started and stopped immediately without any errors in console.
My setting is like this: Dockerfile:

FROM erlang:latest

WORKDIR /project

CMD tail -f /dev/null

docker-compose.yml:

version: '3'
services:
  development:
    build:
      context: .
    volumes:
      - ./:/project
      - build:/project/_build
      - deps:/project/deps

volumes:
  build:
  deps:

.devcontainer/devcontainer.json:

{
    "name": "Erlang dev container",

    "service": "development",
  
    "context": "..",

    "dockerComposeFile": "..\\docker-compose.yml",

    "workspaceFolder": "/project",

    "settings": { 
        "terminal.integrated.shell.linux": "/bin/bash"
    },

    "extensions": []  
}

Why doesn't it work?
PS. I even changed my Dockerfile like this:

FROM erlang:latest

WORKDIR /project

COPY . .

And my docker-compose.yml to this:

version: '3'
services:
  development:
    build:
      context: .

And it still doesn't work.
PS PS. But! When after that I changed in devcontainer.json line:

"dockerComposeFile": "..\\docker-compose.yml",

to:

"dockerFile": "..\\Dockerfile",

Only then my folder was opened in the container by VSCode. But I don't want to COPY . . inside my Dockerfile, I want to add my project's folder as a volume in my docker-compose.yml file. How do I manage this?

qyswt5oh

qyswt5oh1#

我通过将tty:true添加到我的docker-compose服务定义中来解决这个问题,如下所示:

version: '3'
services:
  development:
    build:
      context: .
    tty: true
    volumes: 
      - ./:/project

相关问题