PyCharm 2023.3 Help

Configure an interpreter using Docker Compose

Configuring Docker Compose as a remote interpreter

Let's now define a remote interpreter based on Docker-Compose.

  1. Do one of the following:

    • Click the Python Interpreter selector and choose Add New Interpreter.

    • Press Ctrl+Alt+S to open Settings and go to Project: <project name> | Python Interpreter. Click the Add Interpreter link next to the list of the available interpreters.

    • Click the Python Interpreter selector and choose Interpreter Settings. Click the Add Interpreter link next to the list of the available interpreters.

  2. Select On Docker Compose.

  3. Select an existing Docker configuration in the Server dropdown.

    Alternatively, select Create new and perform the following steps to create a new Docker configuration:

    Create a Docker configuration

    Click The Add button to add a Docker configuration and specify how to connect to the Docker daemon.

    The connection settings depend on your Docker version and operating system. For more information, refer to Docker connection settings.

    The Connection successful message should appear at the bottom of the dialog.

    Docker connection settings

    For more information about mapping local paths to the virtual machine running the Docker daemon when using Docker on Windows or macOS, refer to Virtual machine path mappings for Windows and macOS hosts. You will not be able to use volumes and bind mounts for directories outside of the mapped local path.

    This table is not available on a Linux host, where Docker runs natively and you can mount any directory to the container.

  4. In Configuration files, specify the docker-compose.yml file. Also select the service.

    Creating a new Docker Compose target

    Optionally, specify environment variables and edit the Compose project name in Project name.

  5. Wait until PyCharm creates and configures a new target:

    Configuring                                     a Docker Compose target
  6. Next, select an interpreter to use in the container. You can choose any virtualenv or conda environment that is already configured in the container, or select a system interpreter.

    Selecting a system interpreter for a Docker target
  7. Click OK.

    The configured remote interpreter is added to the list.

Last modified: 11 February 2024