【发布时间】:2020-02-10 10:55:30
【问题描述】:
我无法连接到在使用 vs-code 生成的容器内运行的 django 进程。一切似乎都在工作,我收到了服务器的启动消息,但是当连接到 localhost:8000 时,我没有得到任何响应......
我在启动容器时收到一条发布的端口消息:
发布的端口:8000/tcp -> 127.0.0.1:8000
启动launch.json调试时也是一个干净的开始
系统检查未发现任何问题(0 静音)。 2019 年 10 月 13 日 - 17:45:05 Django 2.2.6 版,使用设置'fpl-django.settings' 在http://127.0.0.1:8000/启动开发服务器退出服务器 使用 CONTROL-C。
为什么我无法访问:localhost:8000 上的站点?
devcontainer.json:
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or the definition README at
// https://github.com/microsoft/vscode-dev-containers/tree/master/containers/docker-existing-dockerfile
{
"name": "Existing Dockerfile",
// Sets the run context to one level up instead of the .devcontainer folder.
"context": "..",
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerFile": "../docker/dev/python/Dockerfile",
// The optional 'runArgs' property can be used to specify additional runtime arguments.
"runArgs": [
// Uncomment the next line to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-in-docker for details.
// "-v","/var/run/docker.sock:/var/run/docker.sock",
// Uncomment the next line if you will be using a ptrace-based debugger like C++, Go, and Rust.
// "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"
// You may want to add a non-root user to your Dockerfile. On Linux, this will prevent
// new files getting created as root. See https://aka.ms/vscode-remote/containers/non-root-user
// for the needed Dockerfile updates and then uncomment the next line.
// "-u", "vscode"
"--network",
"fpl-django_default"
],
// Use 'settings' to set *default* container specific settings.json values on container create.
// You can edit these settings after create using File > Preferences > Settings > Remote.
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
"python.pythonPath": "/usr/local/bin/python",
"python.linting.pylintEnabled": true,
"python.linting.pylintPath": "/usr/local/bin/pylint",
"python.linting.enabled": true
},
// Uncomment the next line if you want to publish any ports.
"appPort": [
8000
],
// Uncomment the next line to run commands after the container is created - for example installing git.
// "postCreateCommand": "apt-get update && apt-get install -y git",
// Add the IDs of extensions you want installed when the container is created in the array below.
"extensions": [
"ms-python.python",
]
}
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"console": "integratedTerminal",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"django": true
}
]
}
【问题讨论】:
-
嗨@TheKaizer,您现在使用的是哪个操作系统?对于 Windows 操作系统,有时我必须使用 192.168.xx 之类的 IP 才能连接到容器。而且我还必须使用以下命令运行我的应用程序:“./manage.py runserver 0.0.0.0:8000 --noreload --nothreading”才能从外部连接
-
@ToanQuocHo 我正在使用 Mac!将尝试您的设置并回复您!
-
您是否尝试过使用'Remote - Container' extension 在您的容器中进行开发?
-
@ToanQuocHo 成功了,你想添加它作为答案以便我接受吗?
-
很高兴听到@TheKaizer
标签: python django visual-studio-code vscode-debugger