0

Working with remote containers in VS Code, I want to start an Ubuntu container (which later starts a Flask server) without the default sleep infinity command, so I can later reach that container from the host.

TL;DR

If I remove the sleep infinity command from the docker-compose.yml, the container can't start, e. g.

Run: docker exec 12d95e1f14877bc4af7fa62e59f81b7ebf0f8983aa357eb077a09bf1951e4370 test -d /root/.vscode-server
Error response from daemon: Container 12d95e1f14877bc4af7fa62e59f81b7ebf0f8983aa357eb077a09bf1951e4370 is not running

.. but WITH the sleep infinity command, the Flask server I'm starting can't forward it's ports with appPort from the devsettings.json.

Related GitHub issues:

https://github.com/microsoft/vscode-remote-release/issues/319

https://github.com/microsoft/vscode-remote-release/issues/259

Setup

image for VS Code container: Docker in Docker compose

image in its Dockerfile: ubuntu:bionic

Dockerfile

FROM ubuntu:bionic

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# Docker Compose version
ARG COMPOSE_VERSION=1.24.0
...
# Configure apt and install packages
RUN apt-get update \
    && apt-get -y install --no-install-recommends apt-utils 2>&1 \
    ....

# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=dialog

I tried to add ENTRYPOINT ["bash", "/bin/bash"] in the Dockerfile, but it has no effect.

devsettings.json

{
    "name": "Docker in Docker Compose",
    "dockerComposeFile": "docker-compose.yml",
    "service": "my-service",
    "workspaceFolder": "/workspace",

    // default command is "sleep infinity", can't use that as Flask should be accessible
    "overrideCommand": false,

    "appPort": ["5000:5000"],

    "extensions": [
        "peterjausovec.vscode-docker",
        "ms-python.python"
    ],
    "settings": {
        "remote.extensionKind": {
            "peterjausovec.vscode-docker": "workspace"
        }
    }
}

docker-compose.yml

version: '3'
services:
  my-service:
    build: 
      context: .
      dockerfile: Dockerfile

    volumes:
      # Update this to wherever you want VS Code to mount the folder of your project
      - ..:/workspace

      # This lets you avoid setting up Git again in the container
      - ~/.gitconfig:/root/.gitconfig

      # Forwards the local Docker socket to the container.
      - /var/run/docker.sock:/var/run/docker.sock 

    # Overrides default command so things don't shut down after the process ends.
    command: sleep infinity
Bennett Dams
  • 6,463
  • 5
  • 25
  • 45
  • I don't see you mentioning any port to be published in your docker-compose file. That could be the reason. – 7_R3X Aug 08 '19 at 13:12
  • @7_R3X The whole time I thought the `appPort` of the `devsettings.json` will do that, but with an additional `docker-compose.yml` it apparently doesn't. Thanks. Feel free to create an answer. – Bennett Dams Aug 08 '19 at 13:23

2 Answers2

1

The reason it doesn't work is that you haven't exposed the port in docker-compose.yml.

The syntax to do it is:

services:
  service_name:
    ports:
      - "8080:80"

Source

7_R3X
  • 3,904
  • 4
  • 25
  • 43
  • I still have no idea why the `appPort` in the `devsettings.json` doesn't expose the ports of the `docker-compose.yml` for the "Docker in Docker compose"-image, as it does usually for a single Dockerfile, but this fixes my issue. – Bennett Dams Aug 08 '19 at 13:31
0

Encounter similar situation while trying to start the jupyter notebook using command, found a way to work around by putting sleep inifinity in the end.

./docker-compose.yml

....
ports:
      - 8888:8888    
command: bash -c "jupyter notebook --ip 0.0.0.0 --port 8888 --no-browser --allow-root && sleep infinity"
WcW
  • 401
  • 5
  • 9