1,078 questions
Problem attaching debugger to Django running in Docker
Alexander Lindgren
1
Reputation point
I'm getting the following error when trying to connect the debugger in vscode to my running Docker container with a Django application.
connect ECONNREFUSED 0.0.0.0:3000
This is from my manage.py file
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'kontorshund.settings')
# start new section
from django.conf import settings
if settings.DEBUG:
if os.environ.get('RUN_MAIN') or os.environ.get('WERKZEUG_RUN_MAIN'):
import debugpy
debugpy.listen(("0.0.0.0", 3000))
This is from my launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Django",
"type": "python",
"request": "attach",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/home/reponame/web"
}
],
"port": 3000,
"host": "0.0.0.0",
}
]
}
This is my Dockerfile
# pull official base image
FROM python:3.9.6
# set work directory
WORKDIR /usr/src/kontorshund
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Locales (local language format for date and time)
RUN apt-get update && apt-get install -y locales && sed -i -e 's/# sv_SE.UTF-8 UTF-8/sv_SE.UTF-8 UTF-8/' /etc/locale.gen && dpkg-reconfigure --frontend=noninteractive locales
ENV LANG sv_SE.UTF-8
ENV LC_ALL sv_SE.UTF-8
# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip install -r requirements.txt
# create the appropriate directories
RUN mkdir -p /home/repoame
ENV HOME=/home/reponame
ENV APP_HOME=/home/reponame/web
RUN mkdir $APP_HOME
RUN mkdir $APP_HOME/staticfiles
RUN mkdir $APP_HOME/mediafiles
WORKDIR $APP_HOME
COPY ./kontorshund/mediafiles $APP_HOME/mediafiles
COPY . $APP_HOME
Microsoft System Center Other
Sign in to answer