question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Debugging in docker container via VSCode docker extension does not work

See original GitHub issue

Actual Behavior

Using RD with dockerd runtime, version 1.0.1. The VSCode docker extension provides a way to run and debug code within a docker container, via a special, automatically generated, run config. I’m using this with a Python/Flask based example app (see https://github.com/SUSE-Rancher-Community/example-flask-sqlite). Generating the run config via the command Docker: Initialize for Docker debugging works fine, but when I start the resulting Docker: Python - Flask run config, it times out after building and launching the container with the error message Timed out waiting for the launcher to connect. Screenshot 2022-02-23 at 08 30 37

Steps to Reproduce

  • Clone repo https://github.com/SUSE-Rancher-Community/example-flask-sqlite
  • Start VSCode in the root directory
  • cmd+shift P -> Docker: Initialize for Docker debugging. Select Python Flask and app.py in the following dialogs.
  • Switch to Run and Debug Tab, select the Docker: Python - Flask run config and start it
  • Wait for the timeout error message to appear
  • Hit cancel

Result

Output of the docker-run: debug task:

> Executing task: docker-build <

> docker build --rm --pull -f "/Users/tim/Documents/src/example-flask-sqlite-tim/Dockerfile" --label "com.microsoft.created-by=visual-studio-code" -t "exampleflasksqlitetim:latest" "/Users/tim/Documents/src/example-flask-sqlite-tim" <

Sending build context to Docker daemon  256.5kB
Step 1/15 : FROM python:3
3: Pulling from library/python
Digest: sha256:f06f47e4bfbda3ba69c4e1ea304f5a3c2a48ee6399ab28c82369fc59eb89410e
Status: Image is up to date for python:3
 ---> dfce7257b7ba
Step 2/15 : RUN apt-get clean     && apt-get -y update
 ---> Using cache
 ---> 2b2cbde40140
Step 3/15 : RUN apt-get -y install     python3-pip
 ---> Using cache
 ---> 976e862476d4
Step 4/15 : WORKDIR /app
 ---> Using cache
 ---> f8b31c9a385f
Step 5/15 : COPY requirements.txt /app/requirements.txt
 ---> Using cache
 ---> 923b0fa4ab6d
Step 6/15 : RUN pip3 install -r requirements.txt
 ---> Using cache
 ---> 5fb48fc7d72c
Step 7/15 : COPY database /app/database
 ---> Using cache
 ---> 359f8e4a41a9
Step 8/15 : COPY handlers /app/handlers
 ---> Using cache
 ---> 20d765c948c5
Step 9/15 : COPY templates /app/templates
 ---> Using cache
 ---> ba7ceda43d45
Step 10/15 : COPY app.py /app/app.py
 ---> Using cache
 ---> c2c7cbc354aa
Step 11/15 : COPY schema.sql /app/schema.sql
 ---> Using cache
 ---> e9899fdd8e02
Step 12/15 : RUN flask init-db
 ---> Using cache
 ---> b6eaf2d19e1d
Step 13/15 : EXPOSE 5000
 ---> Using cache
 ---> 676a9849a4e6
Step 14/15 : CMD [ "python3", "app.py" ]
 ---> Using cache
 ---> f13378e68ec2
Step 15/15 : LABEL com.microsoft.created-by=visual-studio-code
 ---> Using cache
 ---> cea444abb1d9
Successfully built cea444abb1d9
Successfully tagged exampleflasksqlitetim:latest

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them

Terminal will be reused by tasks, press any key to close it.

> Executing task: docker-run: debug <

> docker run -dt -P --name "exampleflasksqlitetim-dev" -e "FLASK_APP=app.py" --label "com.microsoft.created-by=visual-studio-code" -v "/Users/tim/.vscode/extensions/ms-python.python-2022.0.1814523869/pythonFiles/lib/python/debugpy:/debugpy:ro,z" --entrypoint "python3" "exampleflasksqlitetim:latest" <

55f5a686c2997fa9bf9fc23b20c9f04f55fadb803838845e3ad8e76e5c79edba

Terminal will be reused by tasks, press any key to close it.

Output on the Python Debug Console:

/>  /usr/bin/env /usr/local/bin/python3 /Users/tim/.vscode/extensions/ms-azuretools.vscode-docker-1.20.0/resources/python/launcher.py 65281 -- -m flask run --no-debugger --no-reload --host 0.0.0.0 --port 5002 docker exampleflasksqlitetim-dev 
docker exec -d exampleflasksqlitetim-dev python3 /debugpy/launcher host.docker.internal:65281 -- -m flask run --no-debugger --no-reload --host 0.0.0.0 --port 5002
 /> 

Expected Behavior

The local VSCode should be able to connect to the debugger running in the container and show a clickable link in the console output that takes me to the frontend of the app. I should hit the breakpoints set in the code once sending a request to the frontend default route. From there I should be able to step through the code and debug it as if it was running locally.

Additional Information

Similar behavior is observed when attempting to debug a Kubernetes application with Google Cloud Code, which used to work with previous versions of RD (0.6.1 I believe). I’ll open a separate issue for that.

Rancher Desktop Version

1.0.1

Rancher Desktop K8s Version

1.22.6

Which container runtime are you using?

moby (docker cli)

What operating system are you using?

macOS

Operating System / Build Version

Big Sur 11.6

What CPU architecture are you using?

x64

Linux only: what package format did you use to install Rancher Desktop?

No response

Windows User Only

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
timirnichcommented, Mar 8, 2022

With this tip I was able to get it working as well. For some reason VSCode auto-generates the python run command in tasks.json with port 5002. When I change it to 5000, it works.

Side note: in my case the frontend is reachable under http://localhost:49153/, which I assume is an automatic port forward created by RD? The VSCode output says it’s reachable under http://172.17.0.2:5000/, which is probably the IP of the lima VM. Probably worth documenting…

1reaction
timirnichcommented, Feb 24, 2022

Thanks folks - will test with 1.1.0 once available. Also big thanks to @sanyer for the tip with the run statements for apt-get, wasn’t aware.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debug an app running in a Docker container
The Docker extension currently supports debugging Node.js, Python, and .NET applications within Docker containers. Requirements. Scaffolding or pasting a launch ...
Read more >
Docker Tools Tips and Tricks - Visual Studio Code
Docker containers and images have disappeared from Docker view. This is most likely caused by a conflict with another extension called Docker Explorer...
Read more >
Developing inside a Container - Visual Studio Code
The Visual Studio Code Dev Containers extension lets you use a Docker container as a full-featured development environment. It allows you to open...
Read more >
Attach to a running container - Visual Studio Code
Once attached, you can install extensions, edit, and debug like you can when you open a folder in a container using devcontainer.json.
Read more >
Docker extension for Visual Studio Code
Tools for developing and debugging with Docker containers, using Visual Studio Code.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found