microsoft / vscode-remote-release

Visual Studio Code Remote Development: Open any folder in WSL, in a Docker container, or on a remote machine using SSH and take advantage of VS Code's full feature set.
https://aka.ms/vscode-remote
Other
3.67k stars 290 forks source link

Volumes not being mounted when calling docker-compose from dev container #3135

Closed mclean25 closed 4 years ago

mclean25 commented 4 years ago

I'm attempting to build a dev container where you can call docker-compose ... from within the dev container to interact with the workspaces docker-compose file. I've mounted the docker socket from my host to the dev container and can successfully call the host's docker daemon from the container. The issue is that if I run docker-compose commands from the dev container, volumes don't get properly mounted to the containers that docker-compose creates as they would if I had called them from the host.

Calling docker-compose run --entrypoint=bash django from the dev container, then ls -al yields no files or directories inside the container. If I run the same command from the host, all the desired files and folders will be populated in the container.

Steps to Reproduce:

.devcontainer/devcontainer.json:

{
  "name": "Dev Container",
  "context": "..",
  "dockerFile": "Dockerfile",
  "mounts": [
    // allows for control of the host's docker daemon from the container
    "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind",
    "source=${localEnv:HOME}/.ssh,target=/root/.ssh,type=bind,consistency=cached"
  ]
}

.devcontainer/Dockerfile:

FROM nikolaik/python-nodejs:python3.8-nodejs12

RUN apt-get update --quiet --yes \
 && apt-get install \
    --no-install-recommends \
    --yes \
    libmemcached-dev \
  && apt-get install apt-transport-https

COPY requirements.txt requirements-test.txt /.build-deps/
RUN pip install \
    --disable-pip-version-check \
    --no-cache-dir \
    -r /.build-deps/requirements.txt \
    -r /.build-deps/requirements-test.txt
RUN rm -fr /.build-deps/

COPY /frontend/package.json /frontend/package-lock.json /.build-deps/
RUN cd /.build-deps && npm install
RUN mkdir /frontend && cp -r /.build-deps/node_modules /frontend/
RUN mkdir /build-artifacts && cp /.build-deps/package-lock.json /build-artifacts/
RUN rm -fr /.build-deps/

# Installing docker CLI
RUN apt install docker.io -y

# Installing docker compose
RUN curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" \
  -o /usr/local/bin/docker-compose
RUN chmod +x /usr/local/bin/docker-compose

./docker-compose.yml

version: "3.6"
services:
  django: &django-base
    build:
      context: .
      dockerfile: backend/Dockerfile_local
    restart: on-failure
    volumes:
      - .:/web-portal:cached
    depends_on:
      - memcached
      - postgres
      - redis
    networks:
      - main
    ports:
      - 8000:8000 # HTTP port
      - 3000:3000 # ptvsd debugging port
    expose:
      - "3000"
    env_file:
      - variables/django_local.env
  django-worker:
    <<: *django-base
    command: [  # Command matches the one in Procfile
      "rqworker",
      "high",
      "low",
      "normal",
      "--worker-class",
      "rq.worker.HerokuWorker",
      "--job-class",
      "backend.rq.Job",
    ]
    expose: []
    ports: []

Does this issue occur when all extensions are disabled?: No because I need the remote extension.

chrmarti commented 4 years ago

Bind mounts are always relative to the machine / VM the Docker daemon runs on. Instead of . as the source folder, try the absolute path to your workspace folder on your host machine.

(Closing as this is not specific to Remote-Containers.)