0

I have docker file:

FROM anapsix/alpine-java:8_server-jre

RUN apk add --no-cache curl

COPY build/libs/codes-converter-1.0-SNAPSHOT.jar /tmp
COPY mappings.yaml /

ADD load.sh /

RUN chmod +x /load.sh

CMD ["/load.sh"]

load.sh:

#!/bin/bash

exec java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=5005,suspend=n -jar tmp/codes-converter-1.0-SNAPSHOT.jar

sleep 10

curl http://localhost:8090/codes-converter/load-mappings

So basically, i need to connect to one of my endpoints of my java app inside the container after the container startup. But I can't figure out how to do it. Where are my mistakes? This curl command seems not working.

MoonHorse
  • 1,966
  • 2
  • 24
  • 46
Anton Kolosok
  • 482
  • 9
  • 24
  • 2
    you are stuck in `exec java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=5005,suspend=n -jar tmp/codes-converter-1.0-SNAPSHOT.jar` , you ned to add `&` at end of the command – LinPy Aug 05 '19 at 08:20
  • `exec` replaces current shell with given command. Just use: `java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=5005,suspend=n -jar tmp/codes-converter-1.0-SNAPSHOT.jar &` – anubhava Aug 05 '19 at 08:51
  • See https://stackoverflow.com/questions/18351198/what-are-the-uses-of-the-exec-command-in-shell-scripts – Raedwald Aug 05 '19 at 09:00
  • Even remove exec & put it to background could not help I guess, container need this command `java xxx` to be run in foreground to avoid it exit. You need separate `curl` to other parts not in this container, consider modify your design. – atline Aug 05 '19 at 09:01

1 Answers1

0

I guess what you are trying to do is running some kind of data migration after container is launched. I would suggest running it outside of API context as a script of some sort, and only then launching the API after migration is finished.

If yet you insist of running it this way, I can see two different ways of doing it:

  1. Daemonize the time.sleep and curl before the server is launched (i.e making it run in the background, waiting until the server is up)
  2. Create a single cronjob that will be executed in parallel to the server process
gCoh
  • 2,719
  • 1
  • 22
  • 46