Created time: 2014-10-24 Last updated time:

Start building docker image for Java and postgreSQL

Last time, I learned what is docker, and the difference between the docker image and docker container. This time, I'm going to make a image by using "docker build" command.

The image I'm going to make

My application, Alinous Document CMS, is working on the Alinous-Core programming language and the server. It works with following software.

  • Java
  • PostgreSQL

So, I'm going to make docker image with the Java and PostgreSQL at first. This environment is very popular and I guess it is reusable, so I decided to make this image.

After making this image, I'm going to make one to set up Tomcat and Alinous-Core.

Make Dockerfile

In order to build the docker image, the Dockerfile is necessary.

This is the minimum container to make a new environment.

This build file makes a docker image and the image executes "/bin/run.sh" on running. The script "run.sh" is below.


This script launch the postgreSQL server, and run bash at the end of this script. The last bash command blocks to avoid this script finished.

If this script finished, the container also ends.

Build Dockerfile

In order to build the Dockerfile, input following command on the shell.


Run and check the container

After buiding the docker image, run the container with following command.

This command with "-d" option runs the container as daemon. After that, Type the next command to login the shell.


Then you can login the bash shell.

After logging in, you can check if the PostgreSQL works by using psql command. After check it, do not type "exit" if you don't want to stop the container.

In order to detach the shell and return to the local terminal, you have to type Ctrl+p, and Ctrl+q after "p".


Go to Top