简体   繁体   中英

Docker container closes immediately after start

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?

I solved my problem by adding tty:true to my docker-compose service definition, like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM