Calling web service inside Docker

I have in my docker:

  • php-5.6-apache - Apache and php
  • zrrrzzt/docker-unoconv-webservice - webservice which creates pdf from Libre Office documents
  • both containers use network my-network

Creating pfs works fine from shell:

curl --form file=@/var/xxx/documents/output-odt/test.odt http://localhost:3000/unoconv/pdf > /var/xxx/documents/output-odt/test.pdf

But localhost is not recognized properly when its called from my php-5.6-apache container.

It works from php when I use inspected container’s IP address e.g. http://172.18.0.4:3000. But this is not a good solution because IP address changes when server restarts.

Questions:

  • How can I call web service inside Docker?
  • What should be used instead of localhost?
  • Or how can I specify url of container?
  • Or how can I address my-network?

Thanks

You have to understand that a container is an other “host” at least network-wise. Each container have their own, dedicated “localhost”.
To address one container from an other, you have to use it’s name (as in docker run --name myName). Use docker inspect my-network to list the container and their name.
The easiest way is to use a docker-compose.yaml file, because the container name is the service name. So every container started by compose have a name.

Say you started your converter with this command :

docker run --network my-network --name myconverter zrrrzzt/docker-unoconv-webservice

Then from your php-apache container you can do :

curl --form file=@/var/xxx/documents/output-odt/test.odt http://myconverter:3000/unoconv/pdf > /var/xxx/documents/output-odt/test.pdf

Or using a docker-compose.yaml :

version: '3.3'
networks:
  my-network:
services:
  app:
    image: php-5.6-apache
    networks:
      - my-network
    ports:
      - "80:80"

  myconverter:
    image: zrrrzzt/docker-unoconv-webservice
    networks:
      - my-network

thanks for answer. I already specified container name unoconv:

Blockquote

sudo docker run -d -p 3000:3000
–name unoconv
–net my-network
–mount type=bind,source="/usr/share/fonts",target=/usr/share/fonts
–restart unless-stopped
zrrrzzt/docker-unoconv-webservice

Blockquote

curl --form file=@/var/xxx/documents/output-odt/test.odt http://unoconv:3000/unoconv/pdf > /var/xxx/documents/output-odt/test.pdf

Host name was not recognized:
curl: (6) Could not resolve host: unoconv

Now I know where is the problem :smiley:

This commnad works only when called from other container. In my case from php. It doesn’t work from OS shell and that;s why I was confused:

curl --form file=@/var/xxx/documents/output-odt/test.odt http://unoconv:3000/unoconv/pdf > /var/xxx/documents/output-odt/test.pdf

This commnad works only when called from OS shell:
curl --form file=@/var/xxx/documents/output-odt/test.odt http://localhost:3000/unoconv/pdf > /var/xxx/documents/output-odt/test.pdf

Thanks for help