WebStorm 2017.3 Help

Docker

Downloading, installing, and starting Docker

  1. Download Docker from the Docker Official website.
  2. Install and start Docker as described in the Docker Installation Instructions.

If you are using Docker for Windows, enable connection to Docker via the TCP protocol

  1. Right-click the Docker icon /help/img/idea/2017.3/icon_docker.png on the Notification bar:
    docker_settings_access.png
  2. Choose Settings on the context menu:
    docker_access_settings_context_menu.png
  3. In the General section of your system Docker settings, select the Expose daemon on tcp://localhost:2375 without TLS checkbox:
    docker_settings_general_expose_daemon_on_tcp.png

Configuring connection with Docker

Step 1: Create a Docker configuration
On the main menu, choose File | Settings | Build, Execution, Deployment | Docker for Windows and Linux or WebStorm | Preferences | Build, Execution, Deployment | Docker for macOS. On the Docker Settings page that opens, click add.png in the central pane and specify the Docker connection settings. The connection settings depend on your Docker version and operating system.

Docker for macOS Connect to Docker daemon with: Docker for Mac
Docker for Windows Connect to Docker daemon with: TCP socket
Engine API URL: tcp://localhost:2375
Certificates folder: Leave this field empty.
Docker for Linux Connect to Docker daemon with: Unix socket
Docker Toolbox for Windows or macOS Connect to Docker daemon with: Docker Machine
This default setting is fine if the actual name of the executable file is docker-machine and the path to its folder is added to the Path environment variable. Otherwise click /help/img/idea/2017.3/browseButton.png and select the actual executable file in the dialog that opens.

Step 2: Check your connection
If the specified settings are correct, a Connection successful message is displayed. If no message appears, check your Docker Machine executable setting on the Docker | Tools page. For more information, see Docker connection settings.

Step 3 (optional): Map local folders to paths in the container
If you are going to bind container volumes with local folders, on Windows and macOS you need to specify the corresponding mappings in the Path mappings section. For more information, see Working with volume bindings.

Step 4 (optional): Configure Docker Compose
Open the Tools page (File | Settings | Build, Execution, Deployment | Docker | Tools for Windows and Linux or WebStorm | Preferences | Build, Execution, Deployment | Docker | Tools for macOS) and specify the location of your Docker Compose executable. Accept the default setting docker-compose or click /help/img/idea/2017.3/browseButton.png and choose your actual executable in the dialog box that opens.

Connecting to Docker

  1. Open the Docker Tool Window by choosing View | Tool Windows | Docker.
  2. Select a Docker node /help/img/idea/2017.3/iconDocker.png and click /help/img/idea/2017.3/run.png or choose Connect on the context menu.
/help/img/idea/2017.3/ws_ps_51_DockerConnected.png

Managing Docker images

With WebStorm, you can pull and push Docker images, add tags to them, detect IDs of images, as well as search images by parts of their names or ID. All these operations are performed from the dedicated Docker Tool Window (View | Tool Windows | Docker).

To pull an image
In the Docker tool window, select a Docker node /help/img/idea/2017.3/iconDocker.png and click /help/img/idea/2017.3/iconPullImageDocker.png or choose Pull image on the context menu.

/help/img/idea/2017.3/ws_ps_52_DockerPullImage.png
In the dialog that opens, specify the following:
  • In the Registry field, type the URL of the image repository service (e.g. registry.hub.docker.com for Docker Hub) or a Docker Registry configuration.
  • In the Repository field, type the image name.
  • In the Tag field, set a tag to the image tag, e.g. latest.
/help/img/idea/2017.3/ws_53_DockerPullImageDialog.png

To find out the ID of an image
In the Docker tool window, select the image of interest. The image ID is shown on the Properties tab.

/help/img/idea/2017.3/ws_ps_54_DockerImageID.png

To hide images without tags
In the Docker tool window, select the Images node or one of the images and click /help/img/idea/2017.3/iconUntaggedImages.png or choose Untagged images on the context menu.

To find a local image by its name or ID
In the Docker tool window, switch to the left-hand pane and start type the name or ID of an image. WebStorm highlights this text in the names and IDs of the images and containers wherever the text is detected.

/help/img/idea/2017.3/ws_ps_55_DockerFindImage.png

To build an image

  1. Create a Dockerfile for the image that you want to build and open the file in the editor.
  2. To the left of FROM, click /help/img/idea/2017.3/runTwoGreenArrows.png and choose Run on 'Docker'. Your image will be built and run in a container according to your Dockerfile.
/help/img/idea/2017.3/ws_ps_56_DockerfileRun_1.png

To delete a container after the corresponding image is built
In the Docker tool window, select the container and click /help/img/idea/2017.3/delete.png or choose Delete container on the context menu.

To push an image to an image repository

  1. In the Docker tool window, select the image to upload and click /help/img/idea/2017.3/iconPushImageDocker.png or choose Push image on the context menu.
    /help/img/idea/2017.3/ws_ps_57_DockerPushImage.png
  2. In the dialog that opens, specify the Docker Registry configuration to use, the name of the image you are pushing and the attached tag.
    /help/img/idea/2017.3/ws_58_DockerPushDialog.png

To delete one or several images
In the Docker tool window, select the image or images to delete and click /help/img/idea/2017.3/close.png or choose Delete image on the context menu.

Specifying the image repository user account information

When you push an image to a repository you are required to log on to the corresponding server. Your image repository user account info that you have to provide in such cases is stored in what is called a Docker Registry configuration.

Step 1: Start creating a Docker Registry configuration

  1. In the Docker tool window, select the image to upload and click /help/img/idea/2017.3/iconPushImageDocker.png or select a Docker node /help/img/idea/2017.3/iconDocker.png and click /help/img/idea/2017.3/iconPullImageDocker.png, depending on whether you are pushing or pulling an image.
  2. In the Pull image or the Push image dialog that opens, click New.

Step 2: Specify the following Registry Configuration settings

  • In the Address field, type the image repository service URL, e.g. registry.hub.docker.com for Docker Hub or quay.io for Quay.
  • The user name and password for your user account.
  • The email address that you specified when creating your user account.
  • In the Server field, type the name of the associated Docker connection settings (usually, Docker). They are used to connect to the service to check that your user account info is correct.
/help/img/idea/2017.3/ws_59_DockerRegistryDialog.png

Running images from the Docker tool window

  1. In the Docker tool window, select the image to run and click /help/img/idea/2017.3/iconCreateContainerDocker.png or choose Create container on the context menu.
    /help/img/idea/2017.3/ws_ps_62_DockerCreateContainer.png
  2. In the Create container popup, click Create.
  3. In the Create Deployment Configuration dialog that opens specify the following:
    • In the Deployment field, the Docker Image option is selected. This indicates that the run configuration is based on an image available locally.
    • The Image ID field initially shows the ID of the image for which you called the Create container command.
    • In the Container name field, specify the name for the container that will be created. Otherwise, Docker will give your container a name automatically.
    /help/img/idea/2017.3/ws_63_DockerImageDeployment.png
  4. Click Run.

Running images from a Dockerfile

Open your Dockerfile in the editor, click /help/img/idea/2017.3/runTwoGreenArrows.png to the left of FROM, and choose Run on 'Docker'.

/help/img/idea/2017.3/ws_ps_56_DockerfileRun_1.png
WebStorm creates a Dockerfile-based Docker Deployment run/debug configuration with the following main settings:
  • The Deployment field shows your Dockerfile.
  • The name and the tag of the image that will be built, e.g. myimage:latest.
  • The name of the container that will be created. If omitted, Docker will itself give your container a name.
    /help/img/idea/2017.3/ws_61_DockerfileRunConfig.png

Running images via a Docker Deployment run configuration

This method is helpful when you run a multi-container application using a Docker Compose docker-compose.yml file.
To run an image

  1. On the main menu, choose Run | Edit Configurations, click /help/img/idea/2017.3/add.png in the dialog that opens, and choose Docker Deployment from the list.
  2. Complete the configuration settings in the Docker Deployment dialog that opens.
  3. Select the newly created configuration from the list on the toolbar and click /help/img/idea/2017.3/run.png.

Viewing deployment log

After an image is built and the corresponding container is started, select the container in the Docker tool window. The log is shown in the right-hand pane on the Deploy log tab.
/help/img/idea/2017.3/ws_ps_65_DockerDeploymentLog.png

Converting command-line options into container settings JSON

WebStorm provides interface for converting the command-line options for the docker run command into the container settings JSON file, this file can be used for configuring your container at its start.

  1. In the corresponding Docker Deployment run configuration, select the Container tab.
  2. To the right of the JSON file field, click CLI.
    /help/img/idea/2017.3/ws_ps_66_DockerContainerCLI.png
  3. In the dialog that opens, specify the options and the location of the resulting .json file.
    /help/img/idea/2017.3/ws_66_DockerCLIToJSON.png

Running Docker commands in a container

WebStorm provides interface for running docker exec commands.

To run a command

  1. In the Docker tool window, select the container of interest and choose Exec on the context menu.
  2. In the Run command in container popup tool window, click Create.
  3. In the dialog that opens, type the command and click OK. For docker exec [OPTIONS] CONTAINER COMMAND [ARG...] you need to specify only the COMMAND [ARG...] part.
    For example: ls /tmp or mkdir /tmp/my-new-dir.

To start a Shell or Bash session in a container

  1. In the Docker tool window, select the container of interest, choose Exec on the context menu, and then click Create in the pop-up window.
  2. In the dialog that opens, type: /bin/sh or /bin/bash in the Command field.

Working with names and IDs of containers

To find out the ID of a container or an image

  • In the Docker tool window, select the container of interest. Its ID and the ID of its parent image are shown on the Properties tab.
  • To copy the image ID, the container ID and name to the clipboard, select the corresponding row in the table and click /help/img/idea/2017.3/copy.gif. Alternatively, choose Copy image ID or Copy container ID on the context menu.

To rename a container

  1. In the Docker tool window, select the container of interest.
  2. Switch to the Properties tab.
  3. In the Container name field, specify a new name for your container and click Save.

Examining containers

To inspect a container
In the Docker tool window, select the container of interest and choose Inspect on the context menu. The docker inspect command is executed and the detailed low-level information about the container in the JSON format is shown in the Inspection tab.

To view the processes running in a container
In the Docker tool window, select the container of interest and choose Show processes on the context menu. The list of current processes in the container is shown in the Processes tab.

To open a console for an ENTRYPOINT process
In the Docker tool window, select the container of interest and choose Attach on the context menu. The console opens in the Attached console tab and shows the output of the ENTRYPOINT process running inside the container.

To view the container log
In the Docker tool window, select the container of interest and examine its log in the Log tab.

Stopping and restarting containers

To stop a container
In the Docker tool window, select the container of interest and click /help/img/idea/2017.3/stop.gif or choose Stop container on the context menu.

To restart a container
In the Docker tool window, select the container and click /help/img/idea/2017.3/deploymentConsoleDeployAll.png or choose Redeploy on the context menu.

To re-run an image with different settings

  1. In the Docker tool window, select the container in which the image of interest runs and click /help/img/idea/2017.3/edit_config_docker.png or choose Edit Configuration on the context menu.
  2. In the associated Docker Deployment run configuration that opens, edit the settings as necessary.
  3. Click /help/img/idea/2017.3/deploymentConsoleDeployAll.png or choose Redeploy on the context menu.

To hide stopped containers
In the Docker tool window, select the Containers node or one of the containers and click /help/img/idea/2017.3/iconStoppedContainers.png or choose Stopped containers on the context menu.

Working with volume bindings

WebStorm provides interface for binding local folders to container volumes. For Linux it just works, for Windows and macOS some preliminary steps are required.

Step 1. Map local folders to directory paths in the Docker virtual machine's file system (Windows and macOS)

  1. If you are using Docker for Windows, enable drive sharing:
    Open your Docker settings, select the Shared Drives section, and then select the drive (e.g. C) that you want to make available for your containers. Restart Docker.
  2. Open your Docker connection settings: in the Docker tool window, select the Docker node /help/img/idea/2017.3/iconDocker.png and click /help/img/idea/2017.3/edit_config_docker.png.
  3. In the Path mappings section, select an existing mapping and click /help/img/idea/2017.3/edit1.png to edit it, or click /help/img/idea/2017.3/add.png to create a new mapping.
    /help/img/idea/2017.3/ws_69_Docker_path_mappings.png
  4. In the dialog that opens, specify the path to a local folder that you want to make available for volume bindings. In the Virtual machine path type the corresponding directory path in the Docker virtual machine's file system.
    /help/img/idea/2017.3/ws_69_Define_path_mapping.png

Step 2: Specify the volume binding settings in a run configuration

  1. Create a new Docker Deployment run configuration or open an existing one.
  2. Switch to the Container tab, expand the Volume bindings section, and click /help/img/idea/2017.3/add.png.
  3. In the dialog that opens:
    • In the Container path field, type the path to the data volume in the container.
    • In the Host path field type the path to the local directory to be mounted at the specified container path.
    • To suppress writing to the container volume, select the Readonly checkbox.
    /help/img/idea/2017.3/ws_69_DockerVolumeBindingsTomcat.png

Step 3: View and edit volume bindings for a running container

  1. In the Docker tool window, select the container of interest and switch to the Volume Bindings tab.
  2. To create a binding, click /help/img/idea/2017.3/add.png. To edit an existing binding, select it and click /help/img/idea/2017.3/edit1.png.
  3. Specify or edit the settings as necessary.
  4. To apply the changes, click Save.
    /help/img/idea/2017.3/ws_ps_70_DockerVolumeBindingsTomcatDTW.png

Working with port bindings

You can specify the port binding settings in a Docker Deployment run configuration. Then, when your container is running, you can view and change these settings and apply the changes.

Step 1: Specify the port binding settings in a run configuration

  1. Create a new Docker Deployment run configuration or open an existing one.
  2. Select the Container tab and expand the Port bindings section.
  3. To configure an individual binding, click /help/img/idea/2017.3/add.png and specify the following in the dialog that opens:
    • The container port to be mapped.
    • The protocol to use (TCP or UDP).
    • The Host IP.
      To make the port accessible only from your localhost, type localhost or 127.0.0.1. To make the port accessible from other computers on your network as well, type 0.0.0.0.
    • The corresponding host port.
    /help/img/idea/2017.3/ws_71_DockerPortBindingsTomcat.png

Step 2: View and edit the port binding settings for a running container

  1. In the Docker tool window, select the container and switch to the Port Bindings tab.
  2. If the container was started with the Publish all ports option on, to see the port mappings, choose Inspect on the context menu of the container, and then search for "Ports" by pressing Ctrl+F.
  3. To create a new binding, click /help/img/idea/2017.3/add.png. To edit an existing one, select the binding and click /help/img/idea/2017.3/edit1.png. If the Publish all ports option is currently on, turn it off to be able to specify individual port mappings.
  4. For each particular binding, specify the settings as necessary.
  5. To apply the changes, click Save.
    /help/img/idea/2017.3/ws_ps_72_DockerPortBindingsTomcatDTW.png

Working with environment variables

The environment variables are usually set in the Dockerfile associated with the base image that you are using. There are also the environment variables that Docker sets automatically for each new container.

In a Docker Deployment run configuration, you can specify additional variables and redefine the ones that Docker sets. At a later time, when your container is running, you can view and edit the existing variables, and create and set new ones.

Step 1: Specify the environment variables in a run configuration

  1. Create a new Docker Deployment run configuration or open an existing one.
  2. Select the Container tab, expand the Environment variables section, and click /help/img/idea/2017.3/add.png.
  3. In the dialog that opens, specify the variable name and value.
    /help/img/idea/2017.3/ws_73_DockerEnvVarJar.png

Step 2: View and edit the environment variables for a running container

  1. In the Docker tool window, select the container and then select the Environment variables tab.
  2. To create a new variable, click /help/img/idea/2017.3/add.png. To edit an existing one, select the variable and click /help/img/idea/2017.3/edit1.png.
  3. To apply the changes, click Save.
    /help/img/idea/2017.3/74_DockerEnvVarJarDTW.png

Working with links

Links to other containers are specified in a Docker Deployment run configuration.

Step 1: Specify the link settings in a run configuration

  1. Open a Docker Deployment run configuration for the container that you want to link with another container.
  2. Select the Container tab, expand the Links section, and click /help/img/idea/2017.3/add.png.
  3. In the dialog that opens, specify the link name (choose the container to link to) and the alias for the link name.
  4. Start the container by executing the run configuration.

Step 2: View the link information

  1. In the Docker tool window, choose Inspect on the context menu of the container of interest.
  2. Switch to the Inspection tab and press Ctrl+F to search for HostConfig in the inspection results. The link information will be shown in the format "Links" : [ "<container_name>:<link_name_alias>" ].
Alternatively, open the Terminal tool window (Alt+F12) and run the following command: docker inspect -f "{{ .HostConfig.Links }}" <container_name>

Using Docker Compose

WebStorm integrates with Docker Compose and provides interface for running services according to their definitions in docker-compose.yml files.

To run a Docker Compose service via a Docker Deployment configuration

  1. Create a docker-compose.yml file and specify your services.
  2. Create a Docker Deployment run configuration: choose Run | Edit Configurations on the main menu, then click /help/img/idea/2017.3/add.png, and choose Docker Deployment from the list.
  3. Next to Deployment, select your docker-compose.yml file.
    /help/img/idea/2017.3/ws_ps_64_DockerComposeDeployment.png
  4. Launch the run configuration: /help/img/idea/2017.3/run.png.
    /help/img/idea/2017.3/ws_ps_95_DockerComposeRunning.png

To scale a service

  1. In the Docker tool window, select the service you want to scale.
  2. Click /help/img/idea/2017.3/IconDockerScaleService.png or select Scale from the context menu.
    /help/img/idea/2017.3/ws_ps_96_DockerComposeScaleService.png
  3. Specify how many containers you want in the service.
    /help/img/idea/2017.3/ws_ps_97_dockercomposeservicescaled.png

To start or stop a service
In the Docker tool window, select the service of interest.

  • To stop the service, click /help/img/idea/2017.3/stop.gif or select Stop from the context menu.
  • To start the service, click /help/img/idea/2017.3/run.png or select Start from the context menu.
    /help/img/idea/2017.3/ws_ps_98_DockerComposeServiceStart.png

Interacting with containers
Most of the functions that WebStorm provides for working with "independent" containers are also available for the containers within Docker Compose services. To access these functions, use the commands on the context menu of a container and the toolbar icons in the Docker tool window. For more information, see Working with containers.

Troubleshooting

Unable to connect to Docker
Make sure that:

  • Docker is running.
  • Your Docker connection settings are correct.
  • If you are using Docker for Windows:
    In the General section of your Docker settings, the Expose daemon on tcp://localhost:2375 without TLS option is on.
  • If you are using Docker Toolbox:

Unable to pull an image
When trying to pull an image, you may be getting the following message:

Failed to parse dockerCfgFile: <your_home_dir>/.docker/config.json, caused by: ... {"credsStore":"wincred"}
Open the <your_home_dir>/.docker directory and delete the file config.json.

Unable to use Docker Compose
Make sure that the Docker Compose executable setting in your Docker settings is correct.

Unable to use port bindings
Use the EXPOSE Dockerfile command.

My deployment log is empty
If you have another project opened at the moment, you may find your deployment log in that project.

See Also

Last modified: 20 September 2017