Make sure that the following prerequisites are met:
- Docker is installed, as described on the page Docker Docs. You can install Docker on the various platforms:
Before you start working with Docker, make sure that the Docker integration plugin is enabled. The plugin is bundled with PyCharm and is activated by default. If the plugin is not activated, enable it on the Plugins page of the Settings / Preferences Dialog as described in Enabling and Disabling Plugins.
Before you start working with Docker, make sure that the Python Docker plugin is enabled. The plugin is bundled with PyCharm and is activated by default. If the plugin is not activated, enable it on the Plugins page of the Settings / Preferences Dialog as described in Enabling and Disabling Plugins.
Overview of Docker support
The Docker integration plugin adds the following to PyCharm:
- Docker configurations. These are named sets of settings for accessing the Docker Engine API and Docker Compose.
You can create a Docker configuration in two ways:
- Create Docker Deployment run/debug configurations. They let you download and build Docker images, and create and start Docker containers.
To create a Docker Deployment run/debug configuration, do the following: . See the run configuration settings.
- Docker tool window () that lets you manage your Docker images and containers.
- Docker Registry configurations that represent your Docker image repository user accounts.
- Additional setting in the Python run/debug configuration.
Configuring PyCharm to work with Docker
- In the Settings / Preferences dialog, open the Docker page under Build, Execution, Deployment, and click to create a Docker configuration:
- In the Docker page, provide the following information:
- Apply the changes and close the Settings / Preferences dialog.
After that, you can configure a remote interpreter using Docker:
Creating a Docker Deployment run/debug configuration
Having set up Docker, create the run/debug configuration. The Docker Deployment run/debug configuration can be used to download and build the Docker images, to create and start the Docker containers.
First, in the Deployment tab of the Docker Deployment run/debug configuration dialog, specify the following:
- Name. Here it is Start Docker.
- Server. Here Docker server is selected from the drop-down list.
- Deployment. Here Docker Image is selected.
- Image ID . Here it is mysite.
- Container. Here it is Docker .
Next, in the Container tab, specify the necessary parameters.
At this point we are interested in exposing 80 port of the container to be available from our local machine, so we should configure a port binding for that:
Container port: 80, Protocol: tcp, Host IP: empty, Host port: 8080
Apply changes and close the Docker Deployment run/debug configuration dialog.
Working with Docker in PyCharm
As all the tools are installed, and the integration is configured, the recently created Start Docker Run/Debug Configuration can be launched:
The Docker tool window opens, updating you on the provisioning status and the current state of all your Docker containers.