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.

e.g.:

$ docker network create javaapp
451905b63038719be32c3029dd229d02260fdc6f5fcca136c063556d3f3714d4

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

$ 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>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<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="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

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