TEXT

Create Python Dev Container

Contributed by bugyboo

Improved by Laravel Company · 2026-09-07

Improved prompt:

As a seasoned DevOps engineer, your responsibility is to establish a robust and efficient Python development environment using Docker and Visual Studio Code (VS Code) Remote Containers. Your primary task is to create and execute Docker commands for a lightweight Python development container, leveraging the official python:latest-slim-bookworm image.

Your specific objectives are as follows:

  • Interactive Bash Shell: Configure the container to run in interactive mode with a bash shell that remains active and does not terminate immediately. This ensures a persistent shell session within the container.

  • Container Persistence: Name the container 'py-dev-container' and ensure it continues running indefinitely after the initial command completes. Do not allow the container to be automatically removed after the command execution.

  • Volume Mounting: Mount the current working directory (i.e., the folder where this command is being executed) on the host machine as a volume inside the container. The volume must be mapped to the /workspace directory within the container, allowing read-write access for seamless development.

  • Non-Root User: Run the container as a non-root user named 'vscode'. The UID for this user must be set to 1000 for compatibility with the VS Code Remote - Containers extension.

  • Essential Tool Installation: If necessary, install essential development tools inside the container, such as git, curl, and build-essential. However, these tools should only be installed via runtime commands rather than modifying the base image.

  • Host and Container Integrity: Ensure that no files are created on the host machine or inside the container beyond what is strictly necessary for running the environment. The container should be clean and minimal for optimal performance.

  • VS Code Attachability: Configure the container to be easily attachable to VS Code using the Remote - Containers: Attach to Running Container feature. This enables further Python development, debugging, and the usage of VS Code extensions within the container.

You are required to deliver:

  1. The Docker pull command (include the complete command if the image is not already present on the local machine).

  2. The full Docker run command, incorporating all the necessary flags for the configuration described above.

  3. Detailed instructions on how to attach the current VS Code instance on the host to the running container for development purposes, including any required extensions or settings.

Please ensure the user is positioned in the root folder of their Python project on the host machine when executing these commands.

Original prompt (before our improvements)

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.