Set container name in run/debug configuration
Answered
Hi,
I am trying to set the name of the container that is going to spawn via the docker run/debug execution. I think everything else works fine but the spawned container is with a random name and I need it to show with a specific one. If I understand the flow correctly, I must build a docker images first, then create a "remote interpreter" configuration that uses that docker image and set it as the project interpreter. Now when I create a pyramid run/debug configuration, Pycharm knows that it should spawn a container but it does so with a random name.
Can I achieve this in some way?
Regards,
Evgeni
Please sign in to leave a comment.
Hi!
There are number of settings in Python Run/Debug configuration you may setup running Python applications using Docker interpreter. Please take a look for Docker container settings at this help page. However there are no options for setting container name. Please vote and follow this issue.
Thank you Alexander,
Thank you for the response. At least I know I am not missing something. I've put a vote for the linked issue.
For anyone else wondering, a dirty workaround is renaming the container after it is spawned with docker rename <current_name> <new_name> .
EXPLANATION
There is an option with docker compose. Use de COMPOSE_PROJECT_NAME cli variable with you projects name and then pycharm create the container with projectname + docker compose server.
Settings =< project => project interpreter. Create a new one and use docker compose as your interpreter. Then select your docker compose file, service and use COMPOSE_PROJECT_NAME as environment variable. Done
DOCUMENTATION
Was it solved somehow or Jetbrains don't care about it? The same issue in IntelliJ IDEA
Dorosh , this works in current versions. I tested it in PyCharm 2026.2.3 with a Docker interpreter:
1) Open the Python run configuration
2) Click the browse button in the Docker container settings field
3) In Run options, add
--name my-containerafter--entrypoint= --rm4) Click OK
5) Run the configuration
The container starts with the name
my-container. Without--name, Docker gives it a random name.IntelliJ IDEA uses the same Docker support. When a run configuration runs on a Docker target, add
--nameto the Run options field of that target. It should work the same way there.Mikhail Tarabrikov Thanks for your answer. Maybe there was a misunderstanding on my side.
I've configured a single Docker Run Target that I'd like to use as the Project Default for all my microservices.
Since our services communicate within the Docker network using DNS, each container needs a specific name, such as
product-service,user-service, orbilling-service, as shown in the screenshot.Unfortunately, I can't specify a different container name in each Spring Boot Run Configuration, so IntelliJ starts them with randomly generated names.
I can specify
--namein the Docker Run Target's Run options, but that would mean creating a separate Docker Run Target for every microservice.In my case, I'd have to create multiple identical Docker Run Targets with exactly the same parameters, differing only in one parameter:
--name.Is there a way to dynamically pass the container name from the Spring Boot Run Configuration to the shared Docker Run Target? Ideally, I'd like to keep a single Docker Run Target for all microservices without duplicating its configuration.
Dorosh, there is no way to do this today. Java run configurations, Spring Boot included, have no field for per-configuration Docker options, so every container gets the Run options of the target.
For now, each service needs a separate target. To make the copies:
1. Click Manage targets… next to Run on
2. Select the
jdk-21target and click Duplicate3. In the copy, change only
--namein Run options4. In each Spring Boot run configuration, set Run on to the matching target
Containers find each other by name only on a user-defined network, so add
--network <network-name>to Run options in each target. On the default network, a lookup of the container name fails.Also, with
-p 8080:8080in every target, the second container fails to start with "port is already allocated". Give each target a different host port, such as-p 8081:8080.A feature request for per-configuration Docker options is open: IJPL-258885. Vote for the issue to get updates.
Mikhail Tarabrikov Thank you for creating the feature request! Hopefully, it will be implemented.
Regarding port mappings, that was just an example. In our microservices architecture, we have a Spring Boot gateway service, which could use
--name gateway-service -p 8080:8080, while the other services only need their container names since they communicate over the Docker network.Thanks for pointing that out!