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

Dockerrun task overwrites docker entry point with just python3 call not my app invokation #3641

Closed
Jan-Kowalik-mulberryrisk opened this issue Oct 14, 2022 · 15 comments · Fixed by #3798

Comments

@Jan-Kowalik-mulberryrisk

I followed a tutorial for Python in container running and debugging on VSCode from here. But the docker launch configuration that VSCode generates for me does not work. When I start it de launch config with F5 the container entry point is overwritten with a call to python3 only. It does not start my app at all. Please advice, is that a bug in the docker extension?

See more details on my config below. It is all standard generated and not really modified.
In terminal output you can see that it sets entry point to python3

Environment:

  • Win11
  • VSCode 1.72.2
  • Docker extension 1.22.1

Auto generated files:

  • .vscode/tasks.json
{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "docker-build",
			"label": "docker-build",
			"platform": "python",
			"dockerBuild": {
				"tag": "exceltojson:latest",
				"dockerfile": "${workspaceFolder}/Dockerfile",
				"context": "${workspaceFolder}",
				"pull": true
			}
		},
		{
			"type": "docker-run",
			"label": "docker-run: debug",
			"dependsOn": [
				"docker-build"
			],
			"dockerRun": {
				"env": {
					"FLASK_APP": "app.py"
				}
			},
			"python": {
				"args": [
					"run",
					"--no-debugger",
					"--no-reload",
					"--host",
					"0.0.0.0",
					"--port",
					"5000"
				],
				"module": "flask"
			}
		}
	]
}
  • .vscode/launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Flask",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "app.py",
                "FLASK_ENV": "development",
                "FLASK_DEBUG": "0"
            },
            "args": [
                "run",
                "--no-debugger",
                "--no-reload"
            ],
            "jinja": true
        },
        {
            "name": "Docker: Python - Flask",
            "type": "docker",
            "request": "launch",
            "preLaunchTask": "docker-run: debug",
            "python": {
                "pathMappings": [
                    {
                        "localRoot": "${workspaceFolder}",
                        "remoteRoot": "/app"
                    }
                ],
                "projectType": "flask"
            }
        }
    ]
}
  • Dockerfile
# For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3.8-slim

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
COPY requirements.txt .
RUN python -m pip install -r requirements.txt

WORKDIR /app
COPY . /app

# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" 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"]
  • Terminal output:
#11 writing image sha256:5f27eedb9f5e02e98a83e24cc30d3496381050d0a4fae0c5d9d2beeff6df78c4 0.0s done
#11 naming to docker.io/library/exceltojson:latest done
#11 DONE 0.2s

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 "exceltojson-dev" -e "FLASK_APP=app.py" --label "com.microsoft.created-by=visual-studio-code" -v "c:\Users\JanKowalik\.vscode\extensions\ms-python.python-2022.16.1\pythonFiles\lib\python\debugpy:/debugpy:ro,z" --entrypoint "python3" "exceltojson:latest" <

4f811149f9b42456a29b98a6c162bda450a8ba9cf9bf53ab076691fd9ddb6bfb
 *  Terminal will be reused by tasks, press any key to close it. 
  • error dialog:
    image
@Jan-Kowalik-mulberryrisk Jan-Kowalik-mulberryrisk changed the title Dockerrun task overwites docker entry point with just python3 call not my app invokation Dockerrun task overwrites docker entry point with just python3 call not my app invokation Oct 14, 2022
@bwateratmsft
Copy link
Collaborator

Overriding to use python3 as the entrypoint is intentional. The purpose is to launch an idle container--once the debug configuration executes, the app itself will be launched in the container by pydbg.

Still, I'd expect that, following the tutorials, everything should just work, so I'm going to take a look. At a glance everything seems correct so I'm not sure why it's not debugging correctly.

@bwateratmsft
Copy link
Collaborator

I haven't been able to reproduce, and nothing stands out in your config. Are you able to share your app.py or part of it?

@Jan-Kowalik-mulberryrisk
Copy link
Author

Jan-Kowalik-mulberryrisk commented Oct 21, 2022

@bwateratmsft
I reduced it to the simple hello world, there was not much there anyway

from flask import Flask
from flask import request
from werkzeug.middleware.profiler import ProfilerMiddleware

from service.service import start_task
from service.requests import Request

app = Flask(__name__)
app.wsgi_app = ProfilerMiddleware(app.wsgi_app, profile_dir="./code-profiles", sort_by=("cumtime",), restrictions=(0.2,))


@app.route("/", methods=['GET'])
def home():
    return "Hello, Flask"

@Jan-Kowalik-mulberryrisk
Copy link
Author

I will try to make a new project from scratch and see if it helps

@Jan-Kowalik-mulberryrisk
Copy link
Author

It still has the same issue with the simplest Flask app I can do, all the rest is auto generated as above

from flask import Flask

app = Flask(__name__)

@app.route("/", methods=['GET'])
def home():
    return "Hello, Flask"

@Jan-Kowalik-mulberryrisk
Copy link
Author

Have you tried on Win11 with Docker Desktop?

@Jan-Kowalik-mulberryrisk
Copy link
Author

How can I debug this?

@bwateratmsft
Copy link
Collaborator

Yeah, I'm on Win11 with Docker Desktop. What do you have for a Python setup?

@Jan-Kowalik-mulberryrisk
Copy link
Author

python 3 installed via Anaconda

I just had the most basic app start working now. I am not sure what has changed. The first one (this ticket is about) still doesn't, though. I will see if I can get to the element that causes it to break and will message back.

Thanks for your assistance, I appreciate it.

@Jan-Kowalik-mulberryrisk
Copy link
Author

I think I have found the culprit.
It works when I open my code as a folder in VSCode. But once I have it openned via workspace (or as a workspace) then it starts failing as above.

Let me know if it helps with finding the issue and rectifying it, please.

Thanks

@bwateratmsft
Copy link
Collaborator

Good catch! I'll try that out myself and see if I can find out what's going on and if there's a workaround or fix.

@Jan-Kowalik-mulberryrisk
Copy link
Author

There is some additional info that might be useful. My launch and tasks configuration files are located in the project folder at .vscode/ they are not included in the workspace config file

@bwateratmsft
Copy link
Collaborator

Yeah, that was an intentional change we made a few years back. There were problems with launch configs and tasks located in the workspace file (though I'm having trouble remembering what exactly...), the solution was to always do them in .vscode folders within the individual workspace folders.

@bwateratmsft bwateratmsft added this to the 1.24.0 milestone Oct 26, 2022
@bwateratmsft
Copy link
Collaborator

Sorry for the long delay...it looks like this is the same as #2327, but it may actually be solvable now. We can scope configuration fetches to specific workspace folders, which allows this to work.

@danegsta
Copy link
Contributor

A fix for this was just released in version 1.24.0 of the docker extension, although debugging python in a container may still be blocked by an external bug in the python extension tracked here: #3823

@microsoft microsoft locked and limited conversation to collaborators Mar 6, 2023
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