Skip to content

python debug with docker-compose in vscode? #1

Open

Activity

  1. yezhengli-Mr9 commented on Dec 31, 2023

    @yezhengli-Mr9
    Author

    Video Java Debugging in Docker: How to Use VS Code and Docker Compose relevant to spring boot can definitely get debugged even just with DockerFile

    FROM openjdk:8-jdk-alpine
    VOLUME /tmp
    ARG JAVA_OPTS
    ENV JAVA_OPTS=$JAVA_OPTS
    # ENV JAVA_TOOL_OPTIONS -agentlib:jdwp=transport=dt_socket,address=5005,server=y,suspend=n
    COPY target/springbootdebug-0.0.1-SNAPSHOT.jar springbootdebug.jar
    EXPOSE 8080
    EXPOSE 5005
    CMD ["java", "-jar", "springbootdebug.jar"]
    
  2. yezhengli-Mr9 commented on Dec 31, 2023

    @yezhengli-Mr9
    Author

    By referring to
    (1) Java Debugging in Docker: How to Use VS Code and Docker Compose
    (2) https://medium.com/@lassebenninga/how-to-debug-flask-running-in-docker-compose-in-vs-code-ef37f0f516ee
    feel at least two points are important to debug in vscode, specifically for python with docker-compose
    (3) https://code.visualstudio.com/docs/containers/docker-compose for python

    1. launch.json
    {
        // Use IntelliSense to learn about possible attributes.
        // Hover to view descriptions of existing attributes.
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Python: Remote Attach",
                "type": "python",
                "request": "attach",
                "connect": {
                    "host": "localhost",
                    "port": 5678
                },
                "pathMappings": [
                    {
                        "localRoot": "${workspaceFolder}",
                        "remoteRoot": "."
                    }
                ]
            }
        ]
    }

    compared to here

    {
        // Use IntelliSense to learn about possible attributes.
        // Hover to view descriptions of existing attributes.
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
            {
                "type": "java",
                "name": "Debug in Docker",
                "request": "attach",
                "hostName": "localhost",
                "port": "5005"
            }
        ]
    }
    
    1. DockerFile in (2)
      python debug with docker-compose in vscode: Error: Could not locate a Flask application. Use the 'flask --app' option, 'FLASK_APP' environment variable, or a 'wsgi.py' or 'app.py' file in the current directory cookiecutter-flask/cookiecutter-flask#1966
    services:
      flask-dev:
        build:
          context: .
          target: development
          args:
            <<: *build_args
        image: "my_flask_app-development"
        ports:
          - "8080:5000"
          - "2992:2992"
          - "5678:5678"
        <<: *default_volumes

    While (2) has more steps in Dockerfile

    RUN pip install debugpy

    and Add the debugpy command to the launch script
    and package.json

    "scripts": {
        "start": "python -m debugpy --wait-for-client --listen 0.0.0.0:5678 -m flask run --host=0.0.0.0"
      },

    which coincides with hints in (3).

  3. yezhengli-Mr9 commented on Jan 1, 2024

    @yezhengli-Mr9
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions