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 icon docker 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 Docker in WebStorm

Step 1: Create a Docker configuration
In the Settings/Preferences dialog (Ctrl+Alt+S), choose Docker under Build, Execution, Deployment. 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 browseButton 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 browseButton 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 iconDocker and click run or choose Connect on the context menu.
ws ps 51 DockerConnected

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 iconDocker and click iconPullImageDocker or choose Pull image on the context menu.

ws ps 52 DockerPullImage
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.
ws 53 DockerPullImageDialog

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.

ws ps 54 DockerImageID

To hide images without tags
In the Docker tool window, select the Images node or one of the images and click iconUntaggedImages 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.

ws ps 55 DockerFindImage

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 runTwoGreenArrows and choose Run on 'Docker'. Your image will be built and run in a container according to your Dockerfile.
ws ps 56 DockerfileRun 1

To delete a container after the corresponding image is built
In the Docker tool window, select the container and click delete 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 iconPushImageDocker or choose Push image on the context menu.
    ws ps 57 DockerPushImage
  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.
    ws 58 DockerPushDialog

To delete one or several images
In the Docker tool window, select the image or images to delete and click close 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 iconPushImageDocker or select a Docker node iconDocker and click iconPullImageDocker, 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.
ws 59 DockerRegistryDialog

Running images from the Docker tool window

  1. In the Docker tool window, select the image to run and click iconCreateContainerDocker or choose Create container on the context menu.
    ws ps 62 DockerCreateContainer
  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.
    ws 63 DockerImageDeployment
  4. Click Run.

Running images from a Dockerfile

Open your Dockerfile in the editor, click runTwoGreenArrows to the left of FROM, and choose Run on 'Docker'.

ws ps 56 DockerfileRun 1
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.
    ws 61 DockerfileRunConfig

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 add 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 run.

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.
ws ps 65 DockerDeploymentLog

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.
    ws ps 66 DockerContainerCLI
  3. In the dialog that opens, specify the options and the location of the resulting .json file.
    ws 66 DockerCLIToJSON

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 copy. 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 stop or choose Stop container on the context menu.

To restart a container
In the Docker tool window, select the container and click deploymentConsoleDeployAll 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 edit config docker 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 deploymentConsoleDeployAll 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 iconStoppedContainers 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 iconDocker and click edit config docker.
  3. In the Path mappings section, select an existing mapping and click edit1 to edit it, or click add to create a new mapping.
    ws 69 Docker path mappings
  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.
    ws 69 Define path mapping

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 add.
  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.
    ws 69 DockerVolumeBindingsTomcat

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 add. To edit an existing binding, select it and click edit1.
  3. Specify or edit the settings as necessary.
  4. To apply the changes, click Save.
    ws ps 70 DockerVolumeBindingsTomcatDTW

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 add 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.
    ws 71 DockerPortBindingsTomcat

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 add. To edit an existing one, select the binding and click edit1. 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.
    ws ps 72 DockerPortBindingsTomcatDTW

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 add.
  3. In the dialog that opens, specify the variable name and value.
    ws 73 DockerEnvVarJar

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 add. To edit an existing one, select the variable and click edit1.
  3. To apply the changes, click Save.
    74 DockerEnvVarJarDTW

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. In the dialog that opens, specify the link name (choose the container to link to) and the alias for the link name.
  3. 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 add, and choose Docker Deployment from the list.
  3. Next to Deployment, select your docker-compose.yml file.
    ws ps 64 DockerComposeDeployment
  4. Launch the run configuration: run.
    ws ps 95 DockerComposeRunning

To scale a service

  1. In the Docker tool window, select the service you want to scale.
  2. Click IconDockerScaleService or select Scale from the context menu.
    ws ps 96 DockerComposeScaleService
  3. Specify how many containers you want in the service.
    ws ps 97 dockercomposeservicescaled

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

  • To stop the service, click stop or select Stop from the context menu.
  • To start the service, click run or select Start from the context menu.
    ws ps 98 DockerComposeServiceStart

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:
    • Your Docker Machine is running.
    • The Docker Machine executable setting on the Docker | Tools page is correct.

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.

Last modified: 26 March 2018

See Also