I have 3 docker containers, one is a Node-Express app, one is a Python Fast-API app, and one is an opencpu container.
The node-express app can communicate with the opencpu container through the service name. I can use curl and get data back. But the node-express container cannot send get/post requests to the python container.
I can access the python app from my browser at localhost:9000
I can ping the python container from the node-express container using service name and get replies.
but I cannot send get/post requests to the python container from node-express container.
I get this error: curl: (7) Failed to connect to pythonapi port 80: Connection refused
So I'm unsure why I can reach the opencpu container from the node-express container but not the python container, even though I confirmed the python container works through my browser. Everything is in one docker-compose.yml so I believe I should be able to reach the python container with service name. And I can, I can ping it, so why cant I curl?
NPM-Express dockerfile:
FROM node:12-slim
WORKDIR /starter
ENV NODE_ENV development
COPY package.json /starter/package.jso
RUN npm install
RUN apt-get update && apt install nano
COPY .env.example /starter/.env.example
COPY . /starter
CMD ["ls"]
CMD ["npm", "run", "start"]
Opencpu dockerfile:
from opencpu/ubuntu-18.04
Python dockerfile:
FROM python:3.9
WORKDIR /this-app
RUN mkdir app
# COPY ./app ./app
COPY ./app/requirements.txt ./app
WORKDIR /this-app/app
RUN pip install -r requirements.txt
WORKDIR ../
COPY ./app/models ./models
COPY ./app/controllers.py .
COPY ./app/main.py .
CMD ["python", "./main.py"]
EXPOSE 8000
Docker compose file:
version: '3'
services:
web:
build: ./web
ports:
- "8012:8080"
opencpu:
image: opencpu
container_name: opencpu
build:
context: ./R
dockerfile: dockerfile
ports:
- 8014:8004
python-api
image: python-api
build:
context: ./python
dockerfile: dockerfile
ports:
- 9000:8000
Edit
For some reason it works when I specify the port (8000) in the curl command.
This is strange to me since in the docker-compose.yml I specify port mapping of 9000 outside the container to 8000 inside the container.
When I use the browser instead of curl, I go to the domain at port 9000 and the python api works. Yet from inside a different docker container I can only reach the api with port 8000. So inside the docker container the port mapping is not working.
Also curl to opencpu does not need the port specified. So why does the python api need the port specified??