Skip to content

Latest commit

 

History

History
105 lines (65 loc) · 3.81 KB

ch07-intellij.adoc

File metadata and controls

105 lines (65 loc) · 3.81 KB

Docker and IntelliJ IDEA

This chapter will show you basic Docker tooling with IntelliJ IDEA:

  • Pull Docker images

  • Run, stop, delete a Container

  • Build an Image

Note
IntelliJ only supports configuring Docker Engine running using Docker Toolbox. This means that if you are running Docker for Mac or Docker for Windows then IntelliJ cannot be used.

Install Docker Plugin in IDEA

Go to “Preferences”, “Plugins”, “Install JetBrains plugin…​”, search on “docker” and click on “Install”

docker intellij plugin install

Restart IntelliJ IDEA to active plugin.

Click on “Create New Project”, select “Java”, “Web Application”

docker intellij create java project

Click on “Next”, give the project a name “dockercon”, click on “Finish”. This will open up the project in IntelliJ window.

Go to “Preferences”, “Clouds”, add a new deployment by clicking on “+”. Click on “Import credentials from Docker Machine”, “Detect”, and see a successful connection. You may have to check the IP address of your Docker Machine. Find the IP address of your Docker Machine as docker-machine ip <machine-name> and specify the correct IP address here.

docker intellij cloud connection

Go to “View”, “Tool Windows”, “Docker Tooling Window”. Click on “Connect”" to connect with Docker Machine. Make sure Docker Machine is running.

Warning
IDEA does not work with “Docker for Mac” at this time. (ADD BUG #)
docker intellij tool window

Pull an Image

Select top-level node with the name “Docker”, click on “Pull image”

docker intellij pull image

Type an image name, such as arungupta/couchbase, and “OK”

docker intellij repository name

Expand “Containers” and “Images” to see existing running containers and images.

The specified image is now downloaded and shown as well.

Run a Container

Select the downloaded image, click on “Create container”

Select “After launch” and enter the URL as http://192.168.99.100:8091. Make sure to match the IP address of your Docker Machine.

docker intellij deployment after launch

In “Container” tab, add “Port bindings” for 8091:8091

docker intellij container ports

Click on “Run” to run the container.

This will bring up the browser window and display the page http://192.168.99.100:8091 and looks like:

docker intellij run container browser

This image uses Couchbase REST API to configure the Couchbase server.

Right-click on the running container, select “Inspect” to see more details about the container.

docker intellij container inspect

Click on “Stop container” to stop the container and “Delete container” to delete the container.

Build an Image

  1. Refer to the instructions https://www.jetbrains.com/help/idea/2016.1/docker.html

  2. Right-click on the project, create a new directory docker-dir

  3. Artifact

    1. Click on top-right for “Project Structure”

    2. select “Artifacts”

    3. change “Type:” to “Web Application: Archive”

    4. change the name to dockercon

    5. change Output directory to docker-dir

  4. Create “Dockerfile” in this directory. Use the contents

    FROM jboss/wildfly
    
    ADD dockercon.war /opt/jboss/wildfly/standalone/deployments/
  5. “Run”, “Edit Configurations”, add new “Docker Deployment”

    1. “Deployment” tab

      1. Change the name to dockercon

      2. Select “After launch”, change the URL to “http://192.168.99.100:18080/dockercon/index.jsp”;

      3. In “Before launch”, add “Build Artifacts” and select the artifact

    2. “Container” tab

      1. Add “Port bindings” for “8080:18080”

  6. View, Tool Windows, Docker, connect to it

  7. Run the project