Docker Compose is used to run multi-container applications. For example, you can run a web server, a backend database, and your application code as separate services. Each service can be scaled by adding more containers if necessary. This enables you to perform efficient development and testing in a dynamic environment, similar to production.
Enable the Docker plugin
This functionality relies on the Docker plugin, which is bundled and enabled in PyCharm by default. If the relevant features aren't available, make sure that you didn't disable the plugin.
Press Ctrl+Alt+S to open the IDE settings and select.
Open the Installed tab, find the Docker plugin, and select the checkbox next to the plugin name.
Run a multi-container Docker application
Define necessary services in one or several Docker Compose files.
From the main menu, select.
Click , point to Docker and then click Docker-compose.
Specify the Docker Compose files with your service definitions. If necessary, you can define the services that this configuration will start, specify environment variables, and force building of images before starting corresponding containers (that is, add the
--buildoption for the docker-compose up command).
For more information about the available options, see Docker-compose run configuration.
Click OK to save the Docker Compose run configuration, select it in the main toolbar and click or press Shift+F10 to start the configuration.
When Docker Compose runs your multi-container application, you can use the Services tool window to control specific services and interact with containers. The containers that run as part of Docker Compose are listed under the dedicated Compose nodes, not under the Containers node (which is only for standalone containers).
Scale a service
In the Services tool window, select the service you want to scale and click or select Scale from the context menu.
Specify how many containers you want for this service and click OK.
Stop a running service
In the Services tool window, select the service and click or select Stop from the context menu.
Stop all running services
In the Services tool window, select the Compose node and click or select Stop from the context menu.
Bring your application down
In the Services tool window, select the Compose node and click or select Down from the context menu.
This stops and removes containers along with all related networks, volumes, and images.
Open the Docker Compose file that was used to run the application
In the Services tool window, right-click the Compose node or a nested service node and then click Jump to Source in the context menu or press F4.