{"id":7771,"date":"2026-07-30T11:17:38","date_gmt":"2026-07-30T03:17:38","guid":{"rendered":"https:\/\/www.5x44.cn\/?p=7771"},"modified":"2026-07-30T14:33:50","modified_gmt":"2026-07-30T06:33:50","slug":"vscode%e8%bf%9e%e6%8e%a5docker%e5%ae%b9%e5%99%a8%e8%99%9a%e6%8b%9f%e7%8e%af%e5%a2%83","status":"publish","type":"post","link":"https:\/\/www.5x44.cn\/?p=7771","title":{"rendered":"vscode\u8fde\u63a5docker\u5bb9\u5668\u865a\u62df\u73af\u5883"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u4e00\u3001\u5236\u4f5c\u865a\u62df\u73af\u5883\u9700\u8981\u7684\u5bb9\u5668<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># -------- builder --------\nFROM python:3.12.13 AS builder\n\nWORKDIR \/build\nRUN apt-get update &amp;&amp; apt-get install -y --no-install-recommends \\\n    gcc g++ libffi-dev libssl-dev libpq-dev pkg-config default-libmysqlclient-dev \\\n    &amp;&amp; rm -rf \/var\/lib\/apt\/lists\/*\n\t\nCOPY requirements.txt .\nRUN pip install --prefix=\/install --no-cache-dir -r requirements.txt\n# ------- runtime ------------\nFROM your-python:3.12.13\n\n# \u8fd0\u884c\u65f6\u53ea\u9700\u8981\u5e93\uff0c\u4e0d\u9700\u8981 -dev\nRUN apt-get update &amp;&amp; apt-get install -y --no-install-recommends \\\n    libmysqlclient21 \\\n    &amp;&amp; rm -rf \/var\/lib\/apt\/lists\/*\n\nENV PYTHONPATH=\/usr\/local\/lib\/python3.12\/site-packages\nCOPY --from=builder \/install \/usr\/local\nCOPY . \/app\nWORKDIR \/app\nCMD &#91;\"python\", \"main.py\"]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528\u4e86\u591a\u6b21\u6784\u5efa\u7684\u65b9\u6cd5\uff0cbuilder\u90e8\u5206\u4e0b\u8f7d\u4e86\u9700\u8981\u7684\u7f16\u8bd1\u73af\u5883\uff0c\u56e0\u4e3apython\u4e00\u4e9b\u5e93\u662f\u9700\u8981\u7f16\u8bd1\u5b89\u88c5\u7684\u3002runtime\u90e8\u5206\u76f4\u63a5\u8c03\u7528\u57fa\u7840\u955c\u50cf\uff0c\u5c06builder\u90e8\u5206\u7f16\u8bd1\u597d\u7684\u6269\u5c55\u5305\u76f4\u63a5\u590d\u5236\u5230python\u641c\u7d22\u76ee\u5f55\u4e2d\u3002\u8fd9\u79cd\u591a\u6b21\u6784\u5efa\u7684\u65b9\u5f0f\u53ef\u4ee5\u5927\u5e45\u51cf\u5c11\u955c\u50cf\u7684\u5927\u5c0f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u662fpython:3.12.13\u955c\u50cf\u7684Dockerfile<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#\n# NOTE: THIS DOCKERFILE IS GENERATED VIA \"apply-templates.sh\"\n#\n# PLEASE DO NOT EDIT IT DIRECTLY.\n#\n\nFROM debian:bookworm-slim\n\n# \u6e05\u534e\u6e90 - \u76f4\u63a5\u8986\u76d6\nRUN echo \"deb http:\/\/mirrors.tuna.tsinghua.edu.cn\/debian\/ bookworm main contrib non-free non-free-firmware\" &gt; \/etc\/apt\/sources.list &amp;&amp; \\\n    echo \"deb http:\/\/mirrors.tuna.tsinghua.edu.cn\/debian\/ bookworm-updates main contrib non-free non-free-firmware\" &gt;&gt; \/etc\/apt\/sources.list &amp;&amp; \\\n    echo \"deb http:\/\/mirrors.tuna.tsinghua.edu.cn\/debian-security bookworm-security main contrib non-free non-free-firmware\" &gt;&gt; \/etc\/apt\/sources.list\n\n# ensure local python is preferred over distribution python\nENV PATH \/usr\/local\/bin:$PATH\n\n# cannot remove LANG even though https:\/\/bugs.python.org\/issue19846 is fixed\n# last attempted removal of LANG broke many users:\n# https:\/\/github.com\/docker-library\/python\/pull\/570\nENV LANG C.UTF-8\n\n# runtime dependencies\nRUN set -eux; \\\n\tapt-get update; \\\n\tapt-get install -y --no-install-recommends \\\n\t\tca-certificates \\\n\t\tnetbase \\\n\t\ttzdata \\\n\t; \\\n\trm -rf \/var\/lib\/apt\/lists\/*\n\nENV GPG_KEY 7169605F62C751356D054A26A821E680E5FA6305\nENV PYTHON_VERSION 3.12.13\nENV PYTHON_SHA256 c08bc65a81971c1dd5783182826503369466c7e67374d1646519adf05207b684\n\nRUN set -eux; \\\n\t\\\n\tsavedAptMark=\"$(apt-mark showmanual)\"; \\\n\tapt-get update; \\\n\tapt-get install -y --no-install-recommends \\\n\t\tdpkg-dev \\\n\t\tgcc \\\n\t\tgnupg \\\n\t\tlibbluetooth-dev \\\n\t\tlibbz2-dev \\\n\t\tlibc6-dev \\\n\t\tlibdb-dev \\\n\t\tlibffi-dev \\\n\t\tlibgdbm-dev \\\n\t\tliblzma-dev \\\n\t\tlibncursesw5-dev \\\n\t\tlibreadline-dev \\\n\t\tlibsqlite3-dev \\\n\t\tlibssl-dev \\\n\t\tmake \\\n\t\ttk-dev \\\n\t\tuuid-dev \\\n\t\twget \\\n\t\txz-utils \\\n\t\tzlib1g-dev \\\n\t; \\\n\t\\\n\twget -O python.tar.xz \"https:\/\/www.python.org\/ftp\/python\/${PYTHON_VERSION%%&#91;a-z]*}\/Python-$PYTHON_VERSION.tar.xz\"; \\\n\techo \"$PYTHON_SHA256 *python.tar.xz\" | sha256sum -c -; \\\n\twget -O python.tar.xz.asc \"https:\/\/www.python.org\/ftp\/python\/${PYTHON_VERSION%%&#91;a-z]*}\/Python-$PYTHON_VERSION.tar.xz.asc\"; \\\n\tGNUPGHOME=\"$(mktemp -d)\"; export GNUPGHOME; \\\n\tgpg --batch --keyserver hkps:\/\/keys.openpgp.org --recv-keys \"$GPG_KEY\"; \\\n\tgpg --batch --verify python.tar.xz.asc python.tar.xz; \\\n\tgpgconf --kill all; \\\n\trm -rf \"$GNUPGHOME\" python.tar.xz.asc; \\\n\tmkdir -p \/usr\/src\/python; \\\n\ttar --extract --directory \/usr\/src\/python --strip-components=1 --file python.tar.xz; \\\n\trm python.tar.xz; \\\n\t\\\n\tcd \/usr\/src\/python; \\\n\tgnuArch=\"$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)\"; \\\n\t.\/configure \\\n\t\t--build=\"$gnuArch\" \\\n\t\t--enable-loadable-sqlite-extensions \\\n\t\t--enable-optimizations \\\n\t\t--enable-option-checking=fatal \\\n\t\t--enable-shared \\\n\t\t$(test \"${gnuArch%%-*}\" != 'riscv64' &amp;&amp; echo '--with-lto') \\\n\t\t--with-ensurepip \\\n\t; \\\n\tnproc=\"$(nproc)\"; \\\n\tEXTRA_CFLAGS=\"$(dpkg-buildflags --get CFLAGS)\"; \\\n\tLDFLAGS=\"$(dpkg-buildflags --get LDFLAGS)\"; \\\n\tLDFLAGS=\"${LDFLAGS:-} -Wl,--strip-all\"; \\\n\tarch=\"$(dpkg --print-architecture)\"; arch=\"${arch##*-}\"; \\\n# https:\/\/docs.python.org\/3.12\/howto\/perf_profiling.html\n# https:\/\/github.com\/docker-library\/python\/pull\/1000#issuecomment-2597021615\n\tcase \"$arch\" in \\\n\t\tamd64|arm64) \\\n\t\t\t# only add \"-mno-omit-leaf\" on arches that support it\n\t\t\t# https:\/\/gcc.gnu.org\/onlinedocs\/gcc-14.2.0\/gcc\/x86-Options.html#index-momit-leaf-frame-pointer-2\n\t\t\t# https:\/\/gcc.gnu.org\/onlinedocs\/gcc-14.2.0\/gcc\/AArch64-Options.html#index-momit-leaf-frame-pointer\n\t\t\tEXTRA_CFLAGS=\"${EXTRA_CFLAGS:-} -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer\"; \\\n\t\t\t;; \\\n\t\ti386) \\\n\t\t\t# don't enable frame-pointers on 32bit x86 due to performance drop.\n\t\t\t;; \\\n\t\t*) \\\n\t\t\t# other arches don't support \"-mno-omit-leaf\"\n\t\t\tEXTRA_CFLAGS=\"${EXTRA_CFLAGS:-} -fno-omit-frame-pointer\"; \\\n\t\t\t;; \\\n\tesac; \\\n\tmake -j \"$nproc\" \\\n\t\t\"EXTRA_CFLAGS=${EXTRA_CFLAGS:-}\" \\\n\t\t\"LDFLAGS=${LDFLAGS:-}\" \\\n\t; \\\n# https:\/\/github.com\/docker-library\/python\/issues\/784\n# prevent accidental usage of a system installed libpython of the same version\n\trm python; \\\n\tmake -j \"$nproc\" \\\n\t\t\"EXTRA_CFLAGS=${EXTRA_CFLAGS:-}\" \\\n\t\t\"LDFLAGS=${LDFLAGS:-} -Wl,-rpath='\\$\\$ORIGIN\/..\/lib'\" \\\n\t\tpython \\\n\t; \\\n\tmake install; \\\n\t\\\n\tcd \/; \\\n\trm -rf \/usr\/src\/python; \\\n\t\\\n\tfind \/usr\/local -depth \\\n\t\t\\( \\\n\t\t\t\\( -type d -a \\( -name test -o -name tests -o -name idle_test \\) \\) \\\n\t\t\t-o \\( -type f -a \\( -name '*.pyc' -o -name '*.pyo' -o -name 'libpython*.a' \\) \\) \\\n\t\t\\) -exec rm -rf '{}' + \\\n\t; \\\n\t\\\n\tldconfig; \\\n\t\\\n\tapt-mark auto '.*' &gt; \/dev\/null; \\\n\tapt-mark manual $savedAptMark; \\\n\tfind \/usr\/local -type f -executable -not \\( -name '*tkinter*' \\) -exec ldd '{}' ';' \\\n\t\t| awk '\/=&gt;\/ { so = $(NF-1); if (index(so, \"\/usr\/local\/\") == 1) { next }; gsub(\"^\/(usr\/)?\", \"\", so); printf \"*%s\\n\", so }' \\\n\t\t| sort -u \\\n\t\t| xargs -rt dpkg-query --search \\\n# https:\/\/manpages.debian.org\/bookworm\/dpkg\/dpkg-query.1.en.html#S (we ignore diversions and it'll be really unusual for more than one package to provide any given .so file)\n\t\t| awk 'sub(\":$\", \"\", $1) { print $1 }' \\\n\t\t| sort -u \\\n\t\t| xargs -r apt-mark manual \\\n\t; \\\n\tapt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \\\n\trm -rf \/var\/lib\/apt\/lists\/*; \\\n\t\\\n\texport PYTHONDONTWRITEBYTECODE=1; \\\n\tpython3 --version; \\\n\tpip3 --version\n\n# make some useful symlinks that are expected to exist (\"\/usr\/local\/bin\/python\" and friends)\nRUN pip3 config set global.index-url https:\/\/pypi.tuna.tsinghua.edu.cn\/simple\nRUN set -eux; \\\n\tfor src in idle3 pip3 pydoc3 python3 python3-config; do \\\n\t\tdst=\"$(echo \"$src\" | tr -d 3)\"; \\\n\t\t&#91; -s \"\/usr\/local\/bin\/$src\" ]; \\\n\t\t&#91; ! -e \"\/usr\/local\/bin\/$dst\" ]; \\\n\t\tln -svT \"$src\" \"\/usr\/local\/bin\/$dst\"; \\\n\tdone\n\nCMD &#91;\"python3\"]\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e8c\u3001\u6784\u5efa\u597d\u955c\u50cf\u540e\uff0c\u5728vscode\u9879\u76ee\u4e2d\u6dfb\u52a0\u5bb9\u5668\u914d\u7f6e<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u6dfb\u52a0.devcontainer\u76ee\u5f55\uff0c\u5728\u8be5\u76ee\u5f55\u4e0b\u521b\u5efadevcontainer.json\u6587\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"name\": \"local-python-dev\",\n  \"image\": \"gantrycheck:v1\",\n  \"workspaceFolder\": \"\/app\",\n  \"workspaceMount\": \"source=${localWorkspaceFolder},target=\/app,type=bind,consistency=cached\",\n  \"customizations\": {\n    \"vscode\": {\n      \"extensions\": &#91;\"ms-python.python\",\"ms-python.debugpy\",\"ms-python.vscode-pylance\"]\n    }\n  },\n  \"remoteEnv\": {\n      \"PYTHONPATH\": \"\/install\/lib\/python3.12\/site-packages\"\n  },\n  \"settings\": {\n        \"json.schemaDownload.enable\": false\n  },\n  \"mounts\": &#91;],\n  \"runArgs\": &#91;\"--init\"],\n  \"updateRemoteUserUID\": false\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">&#8220;image&#8221;: &#8220;gantrycheck:v1&#8221; \u8bbe\u7f6e\u672c\u5730\u4f7f\u7528\u7684docker\u955c\u50cf\uff0c\u8fd9\u4e2a\u955c\u50cf\u5c31\u662f\u7b2c\u4e00\u6b65\u751f\u6210\u7684\u955c\u50cf\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8220;workspaceFolder&#8221;: &#8220;\/app&#8221; \u6307\u5b9a\u4e86\u5bb9\u5668\u5185\u7684\u5de5\u4f5c\u76ee\u5f55<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8220;workspaceMount&#8221;: &#8220;source=${localWorkspaceFolder},target=\/app,type=bind,consistency=cached&#8221; \u6307\u5b9a\u4e86\u5bb9\u5668\u5185\u5de5\u4f5c\u76ee\u5f55\u7684\u672c\u5730\u6302\u8f7d\u70b9\uff0c\u4e3a\u4e86\u907f\u514d\u6b67\u4e49workspaceFolder\u548cworkspaceMount\u8bbe\u7f6e\u540c\u4e00\u4e2a\u76ee\u5f55\u3002consistency=cached\u6ca1\u67e5\u4ec0\u4e48\u4f5c\u7528\uff0c\u4f46\u662f\u6321\u5899\u8fd9\u4e2a\u914d\u7f6e\u53ef\u4ee5\u7528\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PYTHONPATH\u7528\u4e8e\u8bbe\u7f6e\u5b89\u88c5\u7684python\u6269\u5c55\u641c\u7d22\u8def\u5f84<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8220;json.schemaDownload.enable&#8221;: false \u7531\u4e8e\u8fde\u63a5github\u56f0\u96be\uff0c\u6240\u4ee5\u4e0d\u4e0b\u8f7d\u6a21\u677f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001vscode\u5168\u5c40\u8bbe\u7f6e\uff0c\u6309ctrl+, \u8c03\u51fa\u8bbe\u7f6e\u9762\u677f\uff08\u8be5\u9762\u677f\u662f\u53ef\u4ee5\u7528\u9f20\u6807\u52fe\u9009\uff0c\u4e5f\u53ef\u4ee5\u7f16\u8f91json\u6587\u4ef6\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    \"workbench.colorTheme\": \"Dark Modern\",\n    \"git.openRepositoryInParentFolders\": \"never\",\n    \"diffEditor.maxComputationTime\": 0,\n    \"python.analysis.typeCheckingMode\": \"standard\",\n    \"workbench.editorAssociations\": {\n        \"*.copilotmd\": \"vscode.markdown.preview.editor\",\n        \"*.csv\": \"default\"\n    },\n    \"editor.minimap.enabled\": false,\n    \"terminal.integrated.enableMultiLinePasteWarning\": \"never\",\n    \"git.ignoreMissingGitWarning\": true,\n    \"dev.containers.mountWaylandSocket\": false\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">&#8220;dev.containers.mountWaylandSocket&#8221;: false  \u8fd9\u91cc\u662f\u6838\u5fc3\uff0c\u4e0d\u7136docker\u5728\u6302\u8f7d\u672c\u5730\u76ee\u5f55\u65f6\u4f1a\u63d0\u793a\u9519\u8bef\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e09\u3001ctrl+shift+p\u8c03\u51fa\u547d\u4ee4\uff0c\u9009\u62e9\u201cDev Containers: Reopen in Container\u201d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u65f6\u5c31\u4f1a\u81ea\u52a8\u8fde\u63a5\u5230\u5bb9\u5668\u5185\u90e8\uff08\u6211\u5b89\u88c5\u7684\u662fdocker desktop\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u6709\u4e00\u70b9\u8981\u6ce8\u610f\uff0c\u5982\u679c\u662f\u7eaf\u5185\u7f51\u73af\u5883\uff0c\u4e0d\u80fd\u8fde\u63a5\u4e92\u8054\u7f51\u7684\u8bdd\uff0c\u9700\u8981\u5355\u72ec\u4e0b\u8f7d\u4e00\u4e2avscode-server\uff08\u8fd9\u4e2a\u5305vscode\u4f1a\u5b89\u88c5\u5230\u5bb9\u5668\u4e2d\uff09\uff0c\u5c06\u8be5\u5305\u653e\u5230\u65e5\u5fd7\u63d0\u793a\u9519\u8bef\u7684\u76ee\u5f55\u4e2d\uff0c\u518d\u6b21\u542f\u52a8Reopen in Container\u5c31\u4f1a\u8df3\u8fc7\u4e0b\u8f7d\u8fd9\u6b65\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u5236\u4f5c\u865a\u62df\u73af\u5883\u9700\u8981\u7684\u5bb9\u5668 \u4f7f\u7528\u4e86\u591a\u6b21\u6784\u5efa\u7684\u65b9\u6cd5\uff0cbuilder\u90e8\u5206\u4e0b\u8f7d\u4e86\u9700\u8981\u7684\u7f16\u8bd1\u73af\u5883\uff0c\u56e0\u4e3apython\u4e00\u4e9b\u5e93\u662f\u9700\u8981\u7f16\u8bd1\u5b89\u88c5\u7684\u3002runtime\u90e8\u5206\u76f4\u63a5\u8c03\u7528\u57fa\u7840&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.5x44.cn\/?p=7771\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,15],"tags":[],"class_list":["post-7771","post","type-post","status-publish","format-standard","hentry","category-it","category-python3"],"_links":{"self":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/7771","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7771"}],"version-history":[{"count":7,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/7771\/revisions"}],"predecessor-version":[{"id":7778,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/7771\/revisions\/7778"}],"wp:attachment":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}