Postgres and executable Jar

Hi everyone !

For a school project I’ve to create a docker image with two containers

The first one : An executable .jar with JPA (EclipseLink)
The second : A postgres database

I want to know if there are tutorials or if someone can explain me
how can I do that. I sought for a while, but there’s nothing on the net.

( I don’ really know what I’m supposed to write into persistence.xml and
how the first container is connected to the second)

Thanks you a lot !!

Well, technically you should create two Docker images (docker build) with two containers (docker run).

You need to bake two images. For Java one you might want to start with java official image. As for how to set up your app, that’s out of the scope of Dockerizing it specifically, so I’d figure out how to do it locally, and then consequently how to transfer those steps into a Dockerfile-based setup. Likewise there is postgresql official image.

Consider using Docker Compose to manage the two containers at once. However, simple docker run commands are probably easier to get started with and hack / iterate on quickly.

To connect the containers together use network.


$ docker network create javaapp

$ docker run -d --net javaapp --name myserver nginx

$ docker run --net javaapp nathanleclaire/curl curl myserver
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:05 --:--:--     0<!DOCTYPE html>
<title>Welcome to nginx!</title>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href=""></a>.<br/>
Commercial support is available at
<a href=""></a>.</p>

<p><em>Thank you for using nginx.</em></p>
100   612  100   612    0     0    120      0  0:00:05  0:00:05 --:--:--   99k