Theres a good chance I’m being dumb here, but I have the following endpoint which works in the browser and returns a result:
http://localhost:8000/api/ebay/getSellers
This is on my app
Docker container, and I want to use cURL on my api
container to retrieve the result.
My dockerfile looks like so:
services:
server:
build:
context: .
dockerfile: dockerfiles/prod/nginx.dockerfile
ports:
- "8000:80"
volumes:
- ./src:/var/www/html
- ./nginx/prod/nginx.conf:/etc/nginx/conf.d/default.conf:ro
container_name: toolkit-server
image: my/toolkit-server:latest
depends_on:
- app
- api
app:
build:
context: .
dockerfile: dockerfiles/prod/php.dockerfile
volumes:
- ./src:/var/www/html:delegated
container_name: toolkit-app
image: my/toolkit-app:latest
api:
build:
context: .
dockerfile: dockerfiles/prod/api.dockerfile
ports:
- "8100:80"
volumes:
- ./api:/var/www/html/
container_name: toolkit-api
image: my/toolkit-api:latest
I’ve tried using cURL like so:
http://localhost:8000/api/ebay/getSellers
http://app:8000/api/ebay/getSellers
http://toolkit-app:8000/api/ebay/getSellers
But the respose I get is always:
Failed to connect to toolkit-app port 8000: Connection refused
Is there a way to do this?
Edit:
Sorry to clarify, my curl is within the api
container and I want to query the app
container
2
Answers
The api container is mapping the services port 80 to the external port 8100.
Try to request http://localhost:8100/
That’s because you’re querying the wrong port.
In your compose file, you have this configuration for your
app
container :This block means that you’re mapping the port 80 from the container to the port 8000 on your host. It is always
port_on_host:port_on_container
So if you want to access the
app
container from theapi
container, you need to curl with this url :curl http://app:80/api/ebay/getSellers