0

When deploying docker container I have to start a server inside of it, and post some data from inside the container, using those bash commands (both inside the same Docker container):

screen -dmS screen-name java -jar app.jar

curl -X POST --data-binary "path/to/data" http://127.0.0.1:8082/url/path

When I test bash commands locally -- everything works as suggested. But inside the container I get this error:

#15 431.2 curl: (7) Failed to connect to 127.0.0.1 port 8082: Connection refused

I found the similar question, but there was no solution

A. Vasyukhin
  • 89
  • 2
  • 7
  • What's inside the container? What is the single process that's running in the container? Where are you typing these commands? – David Maze Oct 03 '22 at 13:07
  • 1) Server-jar and some scripts 2) For the purpose of this question we can be sure that only this jar (there is nothing that deployed before) 3) Inside bash-scripts, that I'm execute in RUN command of Dockerfile – A. Vasyukhin Oct 03 '22 at 13:59
  • It seems unusual to me for `screen` to be installed in a container at all, much less to be part of a `RUN` directive? Do you have a [mcve], including enough of the Dockerfile to reproduce the issue? – David Maze Oct 03 '22 at 14:11

1 Answers1

0

I presume you are trying to "talk" to a server of some type you haven't specified which is running inside the same container and not on the docker host.

If so, you could try:

# Get container's IP address
IP=$(hostname -i | awk '{print $1}')

curl -X POST --data-binary "path/to/data" "http://${IP}:8082/url/path"

Here's the simplest example:

docker run -it alpine:latest                                         
/ # hostname -i
172.17.0.2
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432