Over a million developers have joined DZone.

JavaEE Development Using Docker With MyEclipse

DZone's Guide to

JavaEE Development Using Docker With MyEclipse

As the popularity of Docker and containers continues to grow, see how you can incorporate them into the enterprise.

· Java Zone ·
Free Resource

Get the Edge with a Professional Java IDE. 30-day free trial.

Section 1: About Docker

Complex applications are moving to containerization technologies — like Docker — for ease of deployment, simplified management, increased reliability, platform portability and microservices support, so if you’re not deploying in containers yet, you likely will be soon. Docker containers wrap a piece of software in a complete filesystem that contains everything needed to run: code, runtime, system tools, system libraries – anything that can be installed on a server.

Section 2: Installing Docker



The Docker Toolbox

Here's the toolbox download.

Note: For either Mac or Windows, there’s a double-click installer. Download and run all the steps as well as verify/test your installations as described here: (MacWindows). Please ensure that “whale” icon is visible and “hello-world” container is run successfully in step 4 of the installation guide.

Section 3: Installing MyEclipse



Latest MyEclipse installer. (It has a free 30-day trial)


Section 4: Building a Sample Web App

  1. Launch MyEclipse.

  2. Select MyEclipse>Examples On-Demand. The Example tab opens on the MyEclipse Dashboard.


  1. Select the Spring tab and then click Install from the Spring Shopping Cart Example.


  1. Once the installation completes, the SpringShoppingCartExample project is added to your workspace.


Section 5: Creating a Docker Tomcat 7 Container

1. Creating a Dockerfile for the Project

  1. Right-click on SpringShoppingCartExample in the MyEclipse Explorer View and select New>Folder. Name the folder DockerResources.

  2. Rick-click on DockerResources and select New>File. Name the file Dockerfile (exact name and case is important).

  3. Within Dockerfile, add these two lines:

 # We'll be using the curated Tomcat 7 container from DockerHub

FROM tomcat:7 

  1. Your workspace should look like this:


2. Setting up the Terminal for Docker Commands

Using Docker containers involves running a lot of command lines directly in the shell and which can be done easily from within MyEclipse with the Terminal view as detailed below.

  1. Open the application preferences, select Terminal>Local Terminal and in arguments type -l (that’s a dash-el). This ensures the shells you launch in the Terminal view behave like a login shell and get the correct execution path so all the Docker toolbox commands can be found.


  1. Open a Terminal with the working directory of the DockerResources folder created earlier. Right-click on DockerResources and select Show In>Terminal.


  1. The eval command will set up the environment variables so Docker commands will work and the docker version command will simply show what that environment looks like as a test.

$ eval $(docker-machine env default)
$ docker version

Version: 1.11.1
API version: 1.23
Go version: go1.5.4
Git commit: 5604cbe
Built: Tue Apr 26 23:44:17 2016
OS/Arch: darwin/amd64

Version: 1.11.1
API version: 1.23
Go version: go1.5.4
Git commit: 5604cbe
Built: Wed Apr 27 00:34:20 2016
OS/Arch: linux/amd64

Section 6: Testing the Tomcat 7 Docker Container

Build an image that describes Tomcat 7 Docker Container — based on the instructions in the Dockerfile documentation using command line mentioned below.

Note: Image is a detailed definition for a container, akin to how a class is the detailed definition for an instantiated object.

The command lines will:

  1. Build container image.

  2. Put it in a local repository named MyEclipse

  3. Name the image examples.

  4. Create a version with the tag run.

$ docker build -t myeclipse/examples:run

Sending build context to Docker daemon 2.048 kB

Step 1 : FROM tomcat:7

---> 705d4a88eedc

Successfully built 705d4a88eedc

Section 7: Running the Docker Container

  1. Run the following command in your terminal to launch a container based on a new image. This command tells Docker to run the container as a daemon (-d) and to map port 8080 — the default Tomcat port — within the container to port 8080 on the Docker host, which is the virtual machine that runs all the Docker containers. Docker responds by showing the internal ID of our running container.

$ docker run -d -p 8080:8080 myeclipse/examples:run


Tip:  Run the ps command to get a more detailed status for running container.

$ docker ps

CONTAINER ID    IMAGE                COMMAND         CREATED         STATUS          PORTS                NAMES

12b15728e8ad    myeclipse/examples:run   "catalina.sh run"                       9 seconds ago   Up 7 seconds                 >8080/tcp   cranky_mcnulty

The command below tells the Docker host’s IP:

$ docker-machine env

export DOCKER_HOST="tcp://"
export DOCKER_CERT_PATH="/Users/todd/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"


  1. Shut down the Tomcat 7 Docker container

$ docker stop cranky_mcnulty

Section 8: Running a Web App in the Docker Container

1. Configuring a Deployment of SpringShoppingCartExample

  1. To create a new deployment, right-click on the project name in the MyEclipse Explorer and select MyEclipse>Add and Remove Project Deployments…


  1. From the Manage Deployments dialog, click Add… to select a new server type for our deployment.


  1. In the Deploy Modules dialog:

    1. Select to manually define a new server radio button

    2. Under the Basic category, select Externally Launched Server.

    3. Finally, in the Server name field specify Docker Tomcat 7 Container and click the Next button.


  1. The Docker installation does a bit of virtual machine configuration that makes sharing any location under your home directory easy, <UserHomeDir>/Applications/DockerDeployments and then click Finish.


  1. Publish.


  1. The status will change to Synchronized. Hover the mouse on the deployment line, a popup confirms that the application is now deployed to the exact location specified. MyEclipse keeps that location in sync with all the changes made  to the code in workspace, which makes testing changes in the Docker container extremely simple.


2. Launching the Docker Container With Our Deployment

  1. We need to launch Docker container so that it maps local deployment to the correct position in the file position of the container. This is accomplished using data volume mapping that is specified as part of the docker run command using the -v option. The command below is exactly like the one used to launch the Docker container previously except now we’re specifying that the deployment directory of SpingShoppingCartExample be mapped to the correct file system location within the Docker container so that Tomcat will know the application is deployed. The full command looks like this:

docker run -v 
"/Users/todd/Applications/DockerDeployments/SpringShoppingCartExample":/usr/local/tomcat/webapps/SpringShoppingCartExample -p 8080:8080 -d myeclipse/examples:run

  1. Use the internal MyEclipse Web Browser to navigate to and see that the Tomcat 7 Docker container is running the SpringShoppingCartExample. A screenshot of a successful run looks like this:



Final Closing Tip

Now that you are familiar with some key Docker commands, how about a shortcut? MyEclipse 2016 CI 4 introduced the ability to drag and drop often used Docker commands from the Snippets view to the Terminal — a real timesaver!



I hope this has been a useful introduction into Docker containers. And now that we can run SpringShoppingCartExample in the Docker container, I bet you’re thinking it would be really great to be able to debug it easily. Well, we can! I give you the details in my next blog post.

If you have any questions or feedback, I’d love to hear from you. Hit us up on twitter at @MyEclipseIDE or on the MyEclipse forum.

Get the Java IDE that understands code & makes developing enjoyable. Level up your code with IntelliJ IDEA. Download the free trial.

docker ,myeclipse ,java ,web app development

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}