PyCharm 2021.2 Help

Docker

Docker enables developers to deploy applications inside containers for testing code in an environment identical to production. PyCharm provides Docker support using the Docker plugin. The plugin is bundled and enabled by default in PyCharm Professional Edition. For PyCharm Community Edition, you need to install the Docker plugin as described in Manage plugins.

You can run and debug your Python code in the variously configured environments deployed in Docker containers. See Configure an interpreter using Docker for more details about how to configure a Python interpreter using Docker.

Enable Docker support

  1. Install and run Docker.

    For more information, see the Docker documentation.

  2. Ensure that you have a stable Internet connection, so that PyCharm can download and run busybox:latest. Once you have successfully configured Docker, you can go offline.

  3. If you are using Docker for Windows, enable connection to Docker via the TCP protocol: Right-click the Docker icon Docker icon on the Notification bar on the Notification bar, select Settings from the context menu, and then select the Expose daemon on tcp://localhost:2375 without TLS checkbox in the General section of your system Docker settings.

  4. Configure the Docker daemon connection settings:

    • Press Ctrl+Alt+S to open the IDE settings and select Build, Execution, Deployment | Docker.

    • 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, see Docker configuration.

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

      The Docker connection settings
  5. Connect to the Docker daemon.

    The configured Docker connection should appear in the Services tool window (View | Tool Windows | Services or Alt+8). Select the Docker node Docker node and click The Connect button, or select Connect from the context menu.

    The Services tool window, connected to Docker

    To edit the Docker connection settings, select the Docker node and click The Edit Configuration button on the toolbar, or select Edit Configuration from the context menu.

In the Services tool window (View | Tool Windows | Services or Alt+8), you can pull and push images, create and run containers, manage Docker Compose services, and so on. As with other tool windows, you can start typing the name of an image or container to highlight the matching items.

Search for a docker image in the Services tool window

Managing images

Docker images are executable packages for running containers. Depending on your development needs, you can use Docker for the following:

  • Pull pre-built images from a Docker registry

    For example, you can pull an image that runs a Django server container to test how your application will interact with your production environment.

  • Build images locally from a Dockerfile

    For example, you can build an image that runs a container with some specific version of Python to execute your application inside it.

  • Push your images to a Docker registry

    For example, if you want to demonstrate to someone how your application runs in some specific version of the JRE instead of setting up the proper environment, they can run a container from your image.

Images are distributed via the Docker registry. Docker Hub is the default public registry with all of the most common images: various Linux flavors, database management systems, web servers, runtime environments, and so on. There are other public and private Docker registries, and you can also deploy your own registry server.

Configure a Docker registry

  1. Press Ctrl+Alt+S to open the IDE settings and select Build, Execution, Deployment | Docker | Registry.

  2. Click The Add button to add a Docker registry configuration and specify how to connect to the registry. If you specify the credentials, PyCharm will automatically check the connection to the registry. The Connection successful message should appear at the bottom of the dialog.

    The Docker Registry dialog

Pull an image from a Docker registry

  1. In the Services tool window, select the Images node.

  2. Select the Docker registry and specify the repository and tag (name and version of the image, for example, tomcat:latest.

    The Pull Image dialog
  3. Press Ctrl+Enter to run docker pull.

Build an image from a Dockerfile

When you are editing a Dockerfile, PyCharm provides completion for images from the configured registries. You can also hold down Ctrl and click an image name to open its page in a web browser.

  1. Open the Dockerfile from which you want to build the image.

  2. Click Run on Docker in the gutter and select to build the image.

    The Build Image on Docker popup

PyCharm runs the docker build command.

Push an image to a Docker registry

  1. In the Services tool window, select the image that you want to upload and click The Push Image button or select Push Image from the context menu.

  2. Select the Docker registry and specify the repository and tag (name and version of the image, for example, my-app:v2).

    The Push Image context menu
  3. Click OK to run the docker push command.

PyCharm stores images that you pull or build locally and lists them in the Services tool window under Images. When you select an image, you can view its ID or copy it to the clipboard by clicking The Copy to clipboard button on the Properties tab.

Docker image properties

To display detailed information about an image, right-click it and select Inspect from the context menu. PyCharm runs the docker image inspect command and prints the output to the Inspection tab.

Docker image Inspection tab

Images with no tags <none>:<none> can be one of the following:

  • Intermediate images that serve as layers for other images and do not take up any space

  • Dangling images that remain when you rebuild an image based on a newer version of another image. You should regularly prune dangling images to preserve disk space.

To hide untagged images from the list, click The Filter menu on the Docker toolbar, and then click Untagged Images to remove the check mark.

To delete one or several images, select them in the list and click The Delete Image button.

Running containers

Docker containers are runtime instances of the corresponding images. PyCharm uses run configurations to execute the commands that build Docker images and run containers. There are three types of Docker run configurations:

Run a container from an existing image

  1. In the Services tool window, select an image and click The Create container button or select Create Container from the context menu.

    The Create container context menu item
  2. In the Create Container popup, click Create.

  3. In the Create Docker Configuration dialog that opens, you can provide a unique name for the configuration and specify a name for the container. If you leave the Container name field empty, Docker will give it a random unique name.

    The Create Docker Configuration dialog
  4. When you are done, click Run to launch the new configuration.

Run a container from a Dockerfile

  1. Open the Dockerfile from which you want to run the container.

  2. Click Run on Docker in the gutter and select to run the container from this Dockerfile.

    The Run on Docker popup

This creates and starts a run configuration with default settings, which builds an image based on the Dockerfile and then runs a container based on this image.

To create a run configuration with custom settings, click Run on Docker in the gutter and select New Run Configuration. You can specify a custom tag for the built image, as well as a name for the container, and a context folder from which to read the Dockerfile. The context folder can be useful, for example, if you have some artifacts outside of the scope of your Dockerfile, which you would like to add to the file system of the image.

Docker run configurations

Create a Docker run configuration

  1. From the main menu, select Run | Edit Configurations.

  2. In the Run/Debug Configurations dialog, click The Add New Configuration button, point to Docker, and then click the desired type of run configuration.

Use this type of configuration to run a Docker container from a locally existing image that you either pulled or built previously.

Docker uses the docker run command with the following syntax:

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

You can set all the arguments for this command using the options of the Docker Image run configuration.

By default, the Docker Image configuration has the following options:

Item

Description

Name

Specify a name for the run configuration to quickly identify it among others when editing or running.

Allow parallel run

Allow running multiple instances of this run configuration in parallel.

By default, it is disabled, and when you start this configuration while another instance is still running, PyCharm suggests stopping the running instance and starting another one. This is helpful when a run configuration consumes a lot of resources and there is no good reason to run multiple instances.

Store as project file

Save the file with the run configuration settings to share it with other team members. The default location is .idea/runConfigurations. However, if you do not want to share the .idea directory, you can save the configuration to any other directory within the project.

By default, it is disabled, and PyCharm stores run configuration settings in .idea/workspace.xml.

Server

Select the Docker daemon connection to use for the run configuration.

Image ID or name

Specify the identifier or the name of the Docker image from which to create the container.

Container name

Specify an optional name for the container. If empty, Docker will generate a random name for the container.

This is similar to using the --name option with the docker run command.

Before launch

Specify a list of tasks to perform before starting the run configuration. For example, compile some code and build the necessary artifacts, run some external tool or a web browser, and so on.

Click the Add button or press Alt+Insert to add one of the available tasks.

Move tasks in the list using the Up button and the Down button to change the order in which to perform the tasks.

Select a task an click the Edit button to edit the task. Click the Remove button to remove the selected task from the list.

Show this page

Show the run configuration settings before actually starting it.

Activate tool window

Open the Services tool window when you start this run configuration. When disabled, you can open the tool window manually to see the running container: View | Tool Windows | Services or Alt+8.

Use the Modify options menu to add advanced options to the run configuration:

Item

Description

Randomly publish all exposed ports

Publish all exposed container ports to random free ports on the host.

This is similar to using the -P or --publish-all option on the command line.

Bind ports

Map specific container ports to specific ports on the host.

This is similar to using the -p or --publish option on the command line.

Click Browse in the Bind ports field and specify which ports on the host should be mapped to which ports in the container. You can also provide a specific host IP from which the port should be accessible (for example, you can set it to 127.0.0.1 to make it accessible only locally, or set it to 0.0.0.0 to open it for all computers in your network).

Lets say you already have Django running on the host port 5432, and you want to run another instance of Django in a container and access it from the host via port 5433. Binding the host port 5433 to port 5432 in the container is similar to setting the following command-line option:

-p 5433:5432

You can set this option explicitly in the Run options field instead of configuring the Bind ports field.

Entrypoint

Override the default ENTRYPOINT of the image.

This is similar to using the --entrypoint option on the command line.

Command

Override the default CMD of the image.

This is similar to adding the command as an argument for docker run.

Bind mounts

Mount files and directories on the host to a specific location in the container.

This is similar to using the -v or --volume option on the command line.

Click Browse in the Bind mounts field and specify the host directory and the corresponding path in the container where it should be mounted. Select Read only if you want to disable writing to the container volume.

For example, you can mount a local Django directory on the host (Users/Shared/django-data) to some directory inside the container (/var/lib/django-data). Mounting volumes in this manner is similar to setting the following command-line option:

-v Users/Shared/django-data:/var/lib/django-data

You can set this option explicitly in the Run options field instead of configuring the Bind mounts field.

Environment variables

Specify environment variables. There are environment variables associated with the base image that you are using as defined by the ENV instruction in the Dockerfile. There are also environment variables that Docker sets automatically for each new container. Use this field to override any of the variables or specify additional ones.

This is similar to using the -e or --env option on the command line.

Click Browse in the Environment variables field to add names and values for variables.

For example, if you want to connect to Django with a specific username by default (instead of the operating system name of the user running the application), you can set the DJANGO_USER variable to the necessary value. This is similar to setting the following command-line option:

--env DJANGO_USER=%env-var-value

You can set this option explicitly in the Run options field instead of configuring the Environment variables field.

Run options

Set any other supported docker run options.

For example, to connect the container to the my-net network and set the my-app alias for it, specify the following:

--network my-net --network-alias my-app

Attach to container

Attach to the container's standard input, output, and error streams.

This is similar to using the -a or --attach option on the command line.

Show command preview

Preview the resulting command that will be used to execute the run configuration.

Use this type of configuration to build an image from a Dockerfile and then derive a container from this image.

Docker uses the docker build command to build an image from a Dockerfile, and then the docker run command to start a container from it.

By default, the Dockerfile configuration has the following options:

Item

Description

Name

Specify a name for the run configuration to quickly identify it among others when editing or running.

Allow parallel run

Allow running multiple instances of this run configuration in parallel.

By default, it is disabled, and when you start this configuration while another instance is still running, PyCharm suggests stopping the running instance and starting another one. This is helpful when a run configuration consumes a lot of resources and there is no good reason to run multiple instances.

Store as project file

Save the file with the run configuration settings to share it with other team members. The default location is .idea/runConfigurations. However, if you do not want to share the .idea directory, you can save the configuration to any other directory within the project.

By default, it is disabled, and PyCharm stores run configuration settings in .idea/workspace.xml.

Server

Select the Docker daemon connection to use for the run configuration.

Dockerfile

Specify the name and location of the Dockerfile used to build the image.

Image tag

Specify an optional name and tag for the built image.

This can be helpful for referring to the image in the future. If you leave the field blank, the image will have only a random unique identifier.

Container name

Specify an optional name for the container. If empty, Docker will generate a random name for the container.

This is similar to using the --name option with the docker run command.

Before launch

Specify a list of tasks to perform before starting the run configuration. For example, compile some code and build the necessary artifacts, run some external tool or a web browser, and so on.

Click the Add button or press Alt+Insert to add one of the available tasks.

Move tasks in the list using the Up button and the Down button to change the order in which to perform the tasks.

Select a task an click the Edit button to edit the task. Click the Remove button to remove the selected task from the list.

Show this page

Show the run configuration settings before actually starting it.

Activate tool window

Open the Services tool window when you start this run configuration. When disabled, you can open the tool window manually to see the running container: View | Tool Windows | Services or Alt+8.

Use the Modify options menu to add advanced options to the run configuration:

Item

Description

Context folder

Specify a local directory that the daemon will use during the build process. All host paths in the Dockerfile will be processed relative to this directory. By default, if you leave it blank, Docker uses the same directory where the Dockerfile is located.

Build args

Specify values for build-time variable that can be accessed like regular environment variables during the build process but do not persist in the intermediate or final images.

This is similar to using the --build-args option with the docker build command.

These variables must be defined in the Dockerfile with the ARG instruction. For example, you can define a variable for the version of the base image that you are going to use:

ARG PYTAG=latest FROM python:$PYTAG

The PYTAG variable in this case will default to latest and the Dockerfile will produce an image with the latest available version of Python, unless you redefine it as a build-time argument. If you set, PYTAG=3.7, Docker will pull python:3.7 instead, which will run a container with Python version 3.7.

Redefining the PYTAG argument is similar to setting the following command-line option:

--build-arg PYTAG=3.7

Build options

Set any other supported docker build options.

For example, you can specify metadata for the built image with the --label option.

Enable BuildKit (experimental)

Use the BuildKit backend when building the images.

This is similar to setting the DOCKER_BUILDKIT=1 environment variable when invoking the docker build command.

Randomly publish all exposed ports

Publish all exposed container ports to random free ports on the host.

This is similar to using the -P or --publish-all option on the command line.

Bind ports

Map specific container ports to specific ports on the host.

This is similar to using the -p or --publish option on the command line.

Click Browse in the Bind ports field and specify which ports on the host should be mapped to which ports in the container. You can also provide a specific host IP from which the port should be accessible (for example, you can set it to 127.0.0.1 to make it accessible only locally, or set it to 0.0.0.0 to open it for all computers in your network).

Lets say you already have Django running on the host port 5432, and you want to run another instance of Django in a container and access it from the host via port 5433. Binding the host port 5433 to port 5432 in the container is similar to setting the following command-line option:

-p 5433:5432

You can set this option explicitly in the Run options field instead of configuring the Bind ports field.

Entrypoint

Override the default ENTRYPOINT of the image.

This is similar to using the --entrypoint option on the command line.

Command

Override the default CMD of the image.

This is similar to adding the command as an argument for docker run.

Bind mounts

Mount files and directories on the host to a specific location in the container.

This is similar to using the -v or --volume option on the command line.

Click Browse in the Bind mounts field and specify the host directory and the corresponding path in the container where it should be mounted. Select Read only if you want to disable writing to the container volume.

For example, you can mount a local Django directory on the host (Users/Shared/django-data) to some directory inside the container (/var/lib/django-data). Mounting volumes in this manner is similar to setting the following command-line option:

-v Users/Shared/django-data:/var/lib/django-data

You can set this option explicitly in the Run options field instead of configuring the Bind mounts field.

Environment variables

Specify environment variables. There are environment variables associated with the base image that you are using as defined by the ENV instruction in the Dockerfile. There are also environment variables that Docker sets automatically for each new container. Use this field to override any of the variables or specify additional ones.

This is similar to using the -e or --env option on the command line.

Click Browse in the Environment variables field to add names and values for variables.

For example, if you want to connect to Django with a specific username by default (instead of the operating system name of the user running the application), you can set the DJANGO_USER variable to the necessary value. This is similar to setting the following command-line option:

--env DJANGO_USER=%env-var-value

You can set this option explicitly in the Run options field instead of configuring the Environment variables field.

Run options

Set any other supported docker run options.

For example, to connect the container to the my-net network and set the my-app alias for it, specify the following:

--network my-net --network-alias my-app

Attach to container

Attach to the container's standard input, output, and error streams.

This is similar to using the -a or --attach option on the command line.

Show command preview

Preview the resulting command that will be used to execute the run configuration.

Use this type of configuration to run multi-container Docker applications.

Docker uses the docker-compose command to define, configure, and run multi-container applications. The main command that builds, creates, starts, and attaches to containers is docker-compose up.

By default, the Docker-compose configuration has the following options:

Item

Description

Name

Specify a name for the run configuration to quickly identify it among others when editing or running.

Allow parallel run

Allow running multiple instances of this run configuration in parallel.

By default, it is disabled, and when you start this configuration while another instance is still running, PyCharm suggests stopping the running instance and starting another one. This is helpful when a run configuration consumes a lot of resources and there is no good reason to run multiple instances.

Store as project file

Save the file with the run configuration settings to share it with other team members. The default location is .idea/runConfigurations. However, if you do not want to share the .idea directory, you can save the configuration to any other directory within the project.

By default, it is disabled, and PyCharm stores run configuration settings in .idea/workspace.xml.

Server

Select the Docker daemon connection to use for the run configuration.

Compose files

Specify the compose files that define the necessary services. Docker Compose builds the configuration in the specified order, so any subsequent files override and add to the fields of the same service in previous files.

This is similar to using the -f option with the docker-compose command.

Services

Specify the services to build, create, and start.

Click the Browse icon (The Browse icon) to select services that are listed in the YML file.

docker-compose browse icon

Before launch

Specify a list of tasks to perform before starting the run configuration. For example, compile some code and build the necessary artifacts, run some external tool or a web browser, and so on.

Click the Add button or press Alt+Insert to add one of the available tasks.

Move tasks in the list using the Up button and the Down button to change the order in which to perform the tasks.

Select a task an click the Edit button to edit the task. Click the Remove button to remove the selected task from the list.

Show this page

Show the run configuration settings before actually starting it.

Activate tool window

Open the Services tool window when you start this run configuration. When disabled, you can open the tool window manually to see the running container: View | Tool Windows | Services or Alt+8.

Use the Modify options menu to add advanced options to the run configuration:

Item

Description

Project name

Specify an alternate project name for Docker Compose. By default, it is the name of the current directory.

This is similar to using the -p option with the docker-compose command.

Environment variables

Specify the Docker Compose environment variables. These are used only by the Docker Compose process. They are not passed on to any of the containers.

Environment variables file

Specify the path to a custom environment file that defines the Docker Compose environment variables.

By default, Docker Compose looks for a file named .env in the project directory.

This is similar to using the --env-file option with the docker-compose command.

Enable BuildKit (experimental)

Use the BuildKit backend when building the images.

This is similar to setting the DOCKER_BUILDKIT=1 environment variable when invoking the docker build command.

Remove volumes on `down

When stopping and removing containers, also delete named volumes declared in the Docker Compose file and anonymous volumes attached to containers.

This is similar to using the -v or --volumes option with the docker-compose down command.

Enable compatibility mode

Convert v3 service definitions into v2 compatible parameters.

This is similar to using the --compatibility option with the docker-compose command.

Remove images on `down

Configure which images should be removed when stopping and removing containers. You can choose to remove all images used by any service or only images that don't have a custom tag set in the image field.

This is similar to using the --rmi option with the docker-compose down command.

Timeout

Set a timeout in seconds to forcefully terminate containers that won't shutdown gracefully.

Docker usually tries to gracefully terminate any container with SIGTERM, but it might end up running indefinitely. Set a timeout after which Docker should send SIGKILL to force the shutdown.

This is similar to using the -t or --timeout option with the docker-compose up command.

Exit code

Return the exit code of the selected service container.

Whenever a container in the selected service stops, return its exit code and stop all other containers in the service.

This is similar to using the --exit-code-from option with the docker-compose up command.

Override scale

Set the number of containers to start for each service.

This option overrides the scale parameter in the Docker Compose file, if it's present.

This is similar to using the --scale option with the docker-compose up command.

Recreate dependencies

Recreate dependent containers when starting a service.

This is similar to using the --always-recreate-deps option with the docker-compose up command.

Recreate anonymous volumes

Recreate anonymous volumes instead of retrieving data from the previous containers.

This is similar to using the -V or --renew-anon-volumes option with the docker-compose up command.

Remove orphans

Remove containers for services not defined in the Docker Compose file.

This is similar to using the --remove-orphans option with the docker-compose up command.

Start

Configure which services to start:

  • Selected and dependencies: By default, Docker Compose starts all of the specified services and linked services.

  • Start: none: Don't start any services after creating them. This is similar to using the --no-start option with the docker-compose up command.

  • Start: selected services: Don't start any of the linked services. This is similar to using the --no-deps option with the docker-compose up command.

Attach to

Configure for which containers to show output streams:

  • Selected services: By default, Docker Compose attaches to all started containers of the specified services.

  • Attach to: none: Don't attach to any containers. This is similar to using the -d or --detach option with the docker-compose up command.

  • Attach to: selected and dependencies: Attach to containers of the specified services and linked services. This is similar to using the --attach-dependencies option with the docker-compose up command.

Recreate containers

Configure which containers to stop and replace by new ones:

  • Changed configuration: By default, Docker Compose recreates containers only if the corresponding configuration or image has changed.

  • Recreate containers: all: Recreate all containers in the services, even if the corresponding configuration or image hasn't changed. This is similar to using the --force-recreate option with the docker-compose up command.

  • Recreate containers: none: Don't recreate any containers in the services, even if the corresponding configuration has changed. This is similar to using the --no-recreate option with the docker-compose up command.

Build

Configure which images to build before starting containers:

  • Only missing images: By default, Docker Compose only builds images that are not available and uses previously built ones when possible.

  • Build: never: Don't build any images. Always use previously built images or throw an error if some image is not available. This is similar to using the --no-build option with the docker-compose up command.

  • Build: always: Always build images before starting containers. This is similar to using the --build option with the docker-compose up command.

Stop Containers

Configure how to stop containers in a service. By default, Docker Compose doesn't stop other containers in a service. You have to stop them manually.

However, you can choose to stop all containers if any container in a service stops. This is similar to using the --abort-on-container-exit option with the docker-compose up command.

Interacting with containers

Created containers are listed in the Services tool window. By default, the Services tool window displays all containers, including those that are not running. To hide stopped containers from the list, click The Filter button in the toolbar, select Docker, and then click Stopped Containers to remove the checkbox.

When you select a container, you can view the following tabs by default:

Build Log

Shows the deployment log produced by the corresponding Docker run configuration while building the image for the container.

Log

Shows the log messages from the container's standard output streams: STDOUT and STDERR.

For more information, see the docker logs command reference.

Properties

Shows the name and ID of the container, and the ID of the corresponding image.

To copy any property to the clipboard, select it and click The Copy to clipboard button.

You can also specify a new name for the container and click Save. If the container is running, it will stop and get a new name. To run the container with the new name, select it and click The Start Container button. However, the name does not change in the Docker run configuration that is used to create this container.

Environment Variables

Shows the environment variables configured for the container.

To add a new variable, click The Add button. To remove a variable, select it and click The Remove button. To edit an existing variable, select it and click The Edit button.

When you make any changes and click Save, if the container is running, it will stop. To run this container with the new set of variables, select it and click The Start Container button. However, these variables don't change in the Docker run configuration that is used to create this container.

Port Bindings

Show the port bindings configured for this container.

Select Publish all ports to bind all exposed container ports to random free ports on the host. To add a new port binding, click The Add button. To remove a port binding, select it and click The Remove button. To edit an existing port binding, select it and click The Edit button.

When you make any changes and click Save, if the container is running, it will stop. To run this container with the new port bindings, select it and click The Start Container button. However, these bindings don't change in the Docker run configuration that is used to create this container.

Volume Bindings

Show the volume bindings configured for this container.

To add a new volume binding, click The Add button. To remove a volume binding, select it and click The Remove button. To edit an existing volume binding, select it and click The Edit button.

When you make any changes and click Save, if the container is running, it will stop. To run this container with the new volume bindings, select it and click The Start Container button. However, these bindings don't change in the Docker run configuration that is used to create this container.

Files

Browse the files inside a running container.

Select any file and click The View in Editor button to open it remotely in the editor or click The Download to Scratches button to create a copy of the file as a scratch.

Execute a command inside a running container

  1. In the Services tool window, right-click the container name and then click Exec.

  2. In the Run Command in Container popup, click Create and Run to create and execute a new command.

    Alternatively, you can select one of the commands that you ran previously.

  3. In the Exec dialog, type the command and click OK. For example:

    ls /tmp

    List the contents of the /tmp directory

    mkdir /tmp/my-new-dir

    Create the my-new-dir directory inside the /tmp directory

    /bin/bash

    Start a bash session

    The Exec tab with /bin/bash running

For more information, see the docker exec command reference.

View detailed information about a running container

  • In the Services tool window, right-click the container name and then click Inspect.

    The output is rendered as a JSON array on the Inspection tab.

    The Inspection tab

For more information, see the docker inspect command reference.

View processes running in a container

  • In the Services tool window, right-click the container name and then click Show Processes.

    The output is rendered as a JSON array on the Processes tab.

For more information, see the docker top command reference.

Attach a console to the output of an executable container

  • In the Services tool window, right-click the container and then click Attach.

    The console is attached to the output of the ENTRYPOINT process running inside a container, and is rendered on the Attached Console tab.

For more information, see the docker attach command reference.

Docker Compose

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.

Run a multi-container Docker application

  1. Define necessary services in one or several Docker Compose files.

  2. From the main menu, select Run | Edit Configurations.

  3. Click The Add icon, point to Docker and then click Docker-compose.

    The Docker-compose configuration
  4. Specify the Docker Compose files that define services which you want to run in containers. If necessary, you can restrict the services that this configuration will start, specify environment variables, and force building of images before starting corresponding containers (that is, add the --build option for the docker-compose up command).

    For more information about the available options, see Docker-compose.

  5. Click OK to save the Docker Compose run configuration, select it in the main toolbar and click the Run button 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 are listed under the dedicated Compose nodes, not under the Containers node (which is only for standalone containers).

Scale a service

  1. In the Services tool window, select the service you want to scale and click The Scale button or select Scale from the context menu.

  2. 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 The Stop button or select Stop from the context menu.

Stop all running services

  • In the Services tool window, select the Compose node and click The Stop button or select Stop from the context menu.

Bring your application down

  • In the Services tool window, select the Compose node and click The Down button 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.

The Docker-compose run configuration will identify environment files with the .env suffix if they are located in the same directory as the Docker Compose file.

Troubleshooting

If you encounter one of the following problems, try the corresponding suggested solution.

Docker

Reported Problem

Description

Solution

Unable to connect to Docker

Docker is not running, or your Docker connection settings are incorrect.

In the Settings/Preferences dialog Ctrl+Alt+S, select Build, Execution, Deployment | Docker, and select Docker for <your operating system> under Connect to Docker daemon with. For example, if you're on macOS, select Docker for Mac. See more detail in Docker settings.

If you are using Docker Toolbox, make sure that Docker Machine is running and its executable is specified correctly in the Settings/Preferences dialog Ctrl+Alt+S under Build, Execution, Deployment | Docker | Tools.

Docker-composer does not work on Ubuntu using unix socket settings.

Docker-composer reports the following error:

docker.errors.TLSParameterError: Path to a certificate and key files must be provided through the client_config param. TLS configurations should map the Docker CLI client configurations.
  1. Open the project Settings/Preferences (Ctrl+Alt+S).

  2. Go to Build, Execution, Deployment | Docker.

  3. Select TCP socket.

  4. Enter unix:///var/run/docker.sock in the Engine API URL field.

When you try to pull an image, the following message is displayed:

Failed to parse dockerCfgFile: <your_home_dir>/.docker/config.json, caused by: ... {"credsStore":"wincred"}

Invalid Auth config file when using credsStore: http://github.com/docker-java/docker-java/issues/806

Go to <your_home_dir>/.docker directory and delete the config.json file.

Unable to use Docker Compose

Docker Compose executable is specified incorrectly.

Specify Docker Compose executable in the Settings/Preferences dialog Ctrl+Alt+S under Build, Execution, Deployment | Docker | Tools

Unable to use port bindings

Container ports are not exposed.

Use the EXPOSE command in your Dockerfile

High CPU usage while connecting to Docker via services.

When Hyper-V is selected as the backend for the Docker service on Windows, Hyper-V virtual disk files (.vhdx) are constantly scanned by the anti-virus software. This behavior leads to excessive consumption of CPU, even no container is running.

Exclude Hyper-V virtual disk files from the anti-virus scan.

Limitations

The Docker plugin has certain limitations and bugs, however JetBrains is constantly working on fixes and improvements for it. You can find the list of Docker issues in our bug-tracking system and vote for the ones that affect you the most. You can also file your own bugs and feature requests.

Last modified: 17 November 2021