Tutorial – Writing Docker File for Installing Java

What is Docker?

Docker allows you to package an application with all of its dependencies into a standardized unit for software development.

Docker is very useful in development environment because, if you write docker file once you don’t need to write down which and all dependence you need to install for running your application. Just you need to build the docker file in every servers or systems docker uses internet and install all the dependencies and run your application.

In this blog you will be learning how to write docker file to install Java.

This tutorial is very basic, but if java is not installed majority of the application will not run.

We ll be using centos docker image as the base and install java on top of it. Lets start it

Note: This tutorial assumes the docker is up and running.

First create a file called Dockerfile without any extension.

As told before we will use centos as base so,

FROM centos

This command tells docker engine to include centos image to your new image, if centos image is not found locally then docker download’s this image from Docker Hub.

Next you have to be root user to install any software so the docker command for getting root user is

USER root

This command tell docker to run subsequent command in root user,

Note: This doesn’t need any password.

Now its time to install the java – in this we will install java 1.7.0

The Docker command to run any type of commands is RUN

RUN yum install -y java-1.7.0-openjdk-devel

As this is centos we will use yum as installer if any other OS use corresponding command to install eg. Ubuntu – apt-get. Here -y arguments tell yum to install without asking for conformation while installing.

The full docker file can be found in Github link : Docker File

The Docker image with java installed : Dokcer Hub link

Leave a Reply

Your email address will not be published. Required fields are marked *