Debugging won't work with Docker for Windows (WSL 2) on Windows 11 and PyCharm Professional

Answered

Greetings,
I'm having hard time debugging my application using PyCharm. Currently I can run the application within PyCharm (without touching Docker or Windows Terminal), but I can't seem to have IDE attach to application. I have read almost all relevant guides and some discussions, but I am still stuck. I would appreciate any help with up-to-date information. My specific setups is as follows:
- Windows 11
- Docker for Windows (using WSL 2 mode)
- PyCharm Professional
Here is the docker-compose-local.yml:

version: "2.2"
services:
api:
container_name: diglabs-model-api
build:
context: .
dockerfile: Dockerfile.local
volumes:
- ".:/app"
ports:
- "5551:8080"
environment:
- AIRTABLE_API_KEY=${AIRTABLE_API_KEY}
- AWS_ACCESS_KEY=${AWS_ACCESS_KEY}
- AWS_ACCESS_SECRET=${AWS_ACCESS_SECRET}

Here is Dockerfile.local:

FROM amazonlinux

# MAINTANER DIGLabs "a@b.c"

# COPY . /app

VOLUME ["/app"]
WORKDIR /app

RUN yum update -y

RUN yum install -y \
python3 python3-pip python3-devel libXext \
libSM libXrender \
mesa-libGL \
deltarpm

RUN yum groupinstall "Development Tools" -y

ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# RUN source stool_env/bin/activate

# RUN conda install pytorch torchvision -c pytorch

RUN pip3 install uwsgi

COPY ./requirements.txt /tmp/
RUN pip install -r /tmp/requirements.txt --no-cache-dir

RUN pip3 install torch torchvision helper torchsummary keras --no-cache-dir

# Some reason you need to run this.
# RUN pip3 install git+https://github.com/keras-team/keras.git

# RUN curl http://abc.amazonaws.com/weights/weights.zip -o weights.zip
# RUN unzip weights.zip

EXPOSE 8080
ENV PORT=8080

CMD ["python", "app.py"]

I can also add screenshots of Run/Debug configurations, but I currently use Compose Run, setting compose file as the file I shared above. On services, I choose "api".
I have tried to Modify and choose "attach to Selected Services", still the code won't pause on breakpoints. :(

0
2 comments

Hi,
Have you tried using the Python run configuration instead or is it not suitable for your use case?

0

Hi Sergey Karpov I did manage to run it using regular Python configuration combined with some manual env variables, using Docker Python interpreter.

0

Please sign in to leave a comment.