Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tasks.json: dockerRun volumes: support bind? #2271

Closed
eddieparker opened this issue Sep 3, 2020 · 8 comments · Fixed by #2294
Closed

tasks.json: dockerRun volumes: support bind? #2271

eddieparker opened this issue Sep 3, 2020 · 8 comments · Fixed by #2294

Comments

@eddieparker
Copy link

I often find it handy to 'bind' a volume to the host for development purposes. It helps me iterate quickly on things like Flask while in dev mode.

I can't seem to make that happen with the current syntax: it only makes a 'volume' mount. Would it be possible (or is it already somehow?) to expose the 'type' variable so I can bind volumes?

@dbreshears dbreshears added this to the 1.7.0 milestone Sep 3, 2020
@bwateratmsft
Copy link
Contributor

Related to #2259 I think. Probably the best approach for both is to add a catch-all "bring your own parameters" field to the docker-run and docker-build tasks.

@eddieparker
Copy link
Author

That would be great! Or, alternatively if i could somehow have the docker run thing actually use my docker compose setup? I dunno if that's possible however.

@bwateratmsft
Copy link
Contributor

Depending on what you're doing it's possible that you don't need to use the docker-run task, but can instead have your own shell task that calls docker-compose up. Are you using the tasks for debugging or just to get a container running?

We tried to design our debugging experience so that the docker-run tasks are not mandatory--thus, users could come up with their own run tasks if they needed more advanced customization. (If that isn't working then I'd consider that a bug we need to fix.)

@eddieparker
Copy link
Author

I'm exploring the docker debugging in vscode. Can the docker debug use docker compose via shell?

@bwateratmsft
Copy link
Contributor

Most likely yes. Which platform are you debugging? (.NET Core, Node, Python)

@eddieparker
Copy link
Author

Python. A flask app to be specific.

@bwateratmsft
Copy link
Contributor

Gotcha. Your best bet is to make use of the Python attach configuration. Here's a setup that works for me, although it was behaving a little weirdly, it seemed to compose-up then do nothing, then I F5'd again, it'd try compose-up again and say it's up to date, then actually attach.

The entrypoint in docker-compose.debug.yml is important; it is instructing debugpy to start the Flask app up and wait for a debugger to attach (from VSCode).

Dockerfile:

# For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3.8-slim-buster

EXPOSE 5000

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE 1

# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED 1

# Install pip requirements
ADD requirements.txt .
RUN python -m pip install -r requirements.txt

WORKDIR /app
ADD . /app

# Switching to a non-root user, please refer to https://aka.ms/vscode-docker-python-user-rights
RUN useradd appuser && chown -R appuser /app
USER appuser

# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "app:app"]

docker-compose.yml:

version: '3.4'

services:
  flasktasktest:
    image: flasktasktest
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 5000

docker-compose.debug.yml:

version: '3.4'

services:
  flasktasktest:
    image: flasktasktest
    build:
      context: .
      dockerfile: Dockerfile
    entrypoint: /bin/bash
    command: -c "pip install debugpy -t /tmp && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 -m flask run --no-debugger --no-reload --host 0.0.0.0 --port 5000"
    ports:
      - 5000:5000
      - 5678:5678
    environment:
      - FLASK_APP=app.py

tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "Compose Up",
            "command": "docker-compose -f docker-compose.yml -f docker-compose.debug.yml up -d"
        }
    ]
}

launch.json:

{
    "configurations": [
        {
            "name": "Python: Remote Attach",
            "type": "python",
            "request": "attach",
            "connect": {
                "host": "localhost",
                "port": 5678
            },
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "."
                }
            ],
            "preLaunchTask": "Compose Up"
        }
    ]
}

@bwateratmsft
Copy link
Contributor

This is now fixed in Docker extension version 1.7.0.

@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants