Video TutorialsWeb Development TutorialsDocker for Java Development Environment With Ubuntu

Docker for Java Development Environment With Ubuntu

In this article, we will discuss how to set up JDE in a Docker container along with the Java Development Environment with Ubuntu, how to download an image straight from the Docker hub and how to look into Docker file so that we can build back and run our container. In order to do that we need some essential Docker commands, every Java developer who wants to work with Docker needs to know the commands.

Why should we run IDE and developer tools in a container?

Well, we all know the pain of creating our developer environment, whether be its first day on the job or if you work on your laptop you have to re-configure the environment. There are many different environments whether it is Mac or Linux; it doesn’t matter because you can always find a way to run Docker. Here we will use Ubuntu version 16.04 and NetBeans 8.2

Different ways to set up our Environment:

  • You need to have installed Docker in your device to run the commands.
  • Type the following code to get the docker image: docker pull mvpjava/NetBeans: 8.2.
  • This code will first check in the local system whether it is already there. If it is not then it will automatically download from the Docker hub. Once you have an image, you can now create a Docker container.
  • The images are lightweight, fast. You don’t have to be worried about breaking about host file system.
  • Always make sure that you download that you trust, an official image from the Docker hub.
  • If you want to vi the Docker file type the following command: dockerfiles/netbeans8.2/alpine$ vi Dockerfile

The output will be as follows:

set up our environment

List the Docker Images:

  • To see the list of Docker Images type: docker images

docker Images

  • Run the Docker Container:

In order to run the Docker container, for Graphical User Interface running inside a Docker container is a bit verbose. So to make it easy, tuck it in a script called NetBeans docker run. Type the following command: – to change Directory type: alpine $ cd, then
cd scripts/

Docker Container

  • to create batch:
  • xhost= because it is a GUI has to interact with x server
  • echo= just to make sure that it is executing
  • docker run= run this command and create a container
  • –rm –d\ = it is the argument i.e. remove the container once you are done with it. You can recreate the container as many times as you want.
  • -e DISPLAY= -e stands for environment and DISPLAY which allows us to interact with the x server.
  • The rest of the stuff is called volume mount points. It mounts your directory on the host file system – to the directory inside the container
  • — name NetBeans \ = used to give a name to the container.
  • Netbeans: 8.2= to reference the name of the Docker image.

To run the container application:

To run the application type: netbeansDockerRun.sh
NetBeans will be started successfully.

Access the home directory:

If you go to your home directory, you will see all your NetBeans projects there as shown in the below image. To access the home directory type: cd and ls

home directory

To check Integration Service of Docker:

  • Create a new project “java application”

java application

To see if the code is able to compile and all the environment variables are set up properly, the JDK’s are up and running type the following command:

JDK’s

In the output window, you will see “hi docker”. This confirms that the code is going well.

  • Go to the services tab and you will see a Docker server in NetBeans 8.2 which allows you to interact with your Docker host. See the below image

NetBeans 8.2

  • Here you will see all the images, right click on it you will see more options like run it, push it, tag it, etc.
  • Similarly, with the containers, you can see NetBeans is running.

NetBeans

  • If you will click on Add Docker the below image will show up:

Add Docker

    • When you will click on Test Connection you will get the message of “Cannot establish connection” and that is because of two reasons.
      1. Your Docker host is not actually running in the container, it is running on the host
      2. Docker Daemon is not accepting Docker connections.To Solve this problem configure it to the host to connect via TCP socket.

To Solve this problem configure it to the host to connect via TCP socket.

  • The IP you should be using is 172.17.0.1 as shown below when you will type ifconfig in the console window.

ifconfig

  • Once you change the URL it will establish the connection. Refer to the image shown below.

connection

To close the Docker container:
You can either close it by clicking on the file tab and click on exit, it will close the Docker container automatically.
Or
Type the following command: docker ps
docker stop netbeans //NetBeans being the name of the container.

Now if you type again the docker ps command you will notice the code has vanished reason being the same as discussed above i.e. – – rm

netbeans (2)

  • If we remove the – – rm command then we will see that it is stuck around and the output will be as follows:

output

There are not many commands used. Either you are pulling it from docker hub, you rebuilding the Docker file creating an image or running it.so it all depends that ‘- – rm’ switch is present or not.

Docker for Java Development Environment –Advantages:

Docker involves faster and unchallenging efforts for the development, testing and deploying the applications within several environments. It lets you access the advantages like the applications will be flexible and isolated. The perfect environment you need to create and test. When you are using Docker for development purpose you can also use editor and IDE tools simultaneously. Three different type of Java applications can be compiled and run without installing without the special tools like Maven, JDK or Gradle.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Exclusive content

- Advertisement -

Latest article

21,501FansLike
4,106FollowersFollow
106,000SubscribersSubscribe

More article

- Advertisement -