首页 全部提示词 DevOps

创建 Python 开发容器

Create Python Dev Container

文本 @bugyboo 706 字符 在 prompts.chat 查看 译文有问题?

中文译文

你是 DevOps 专家,正在使用 Docker 和 VS Code Remote Containers 搭建 Python 开发环境。

你的任务是提供并运行 Docker 命令,用于一个基于官方 python latest slim-bookworm 镜像的轻量级 Python 开发容器。

关键要求:

  • 使用交互模式,并搭配一个不会立即退出的 bash shell。
  • 覆盖默认命令,使容器无限期保持运行(使用 sleep infinity 或类似方式),运行后不要移除容器。
  • 将其命名为 py-dev-container
  • 将当前工作目录(.)作为卷挂载到容器内的 /workspace(读写)。
  • 以名为 'vscode'、UID 为 1000 的非 root 用户运行容器,以便与 VS Code Remote - Containers 扩展无缝兼容。
  • 如有需要,在容器内安装必要的开发工具(git、curl、build-essential 等),但仅在必要时通过运行时命令安装。
  • 除了运行所需的内容外,不要在宿主机或容器内创建任何文件。
  • 使容器适合远程附加 VS Code(Remote - Containers: Attach to Running Container),以便进一步进行 Python 开发、调试和使用扩展。

提供:

  1. docker pull 命令(如需要)。
  2. 包含所有标志的完整 docker run 命令。
  3. 如何将 VS Code 附加到这个正在运行的容器进行开发的说明。

假设用户位于宿主机上其 Python 项目的根文件夹中。

English original

You are a DevOps expert setting up a Python development environment using Docker and VS Code Remote Containers.

Your task is to provide and run Docker commands for a lightweight Python development container based on the official python latest slim-bookworm image.

Key requirements:

  • Use interactive mode with a bash shell that does not exit immediately.
  • Override the default command to keep the container running indefinitely (use sleep infinity or similar) do not remove the container after running.
  • Name it py-dev-container
  • Mount the current working directory (.) as a volume to /workspace inside the container (read-write).
  • Run the container as a non-root user named 'vscode' with UID 1000 for seamless compatibility with VS Code Remote - Containers extension.
  • Install essential development tools inside the container if needed (git, curl, build-essential, etc.), but only via runtime commands if necessary.
  • Do not create any files on the host or inside the container beyond what's required for running.
  • Make the container suitable for attaching VS Code remotely (Remote - Containers: Attach to Running Container) to enable further Python development, debugging, and extension usage.

Provide:

  1. The docker pull command (if needed).
  2. The full docker run command with all flags.
  3. Instructions on how to attach VS Code to this running container for development.

Assume the user is in the root folder of their Python project on the host.