I’m a bit new to docker and I’m messing around with it. I currently have a server being ran on port 5000
in another container. This server is being ran with express and uses JavaScript. I’m trying to send requests to that server with python. I tried using both localhost:5000
and 127.0.0.1:5000
but neither of these seems to work. What can I do? I noticed if I run the python code without docker it works perfectly fine.
Python Docker File:
FROM ubuntu:latest
RUN apt update
RUN apt install python3 -y
RUN apt-get install -y python3-pip
WORKDIR /usr/app/src
COPY . .
RUN pip install discum
RUN pip install python-dotenv
EXPOSE 5000
CMD ["python3", "./src/index.py"]
JavaScript Docker File:
FROM node:latest
WORKDIR /usr/src/app
COPY package.json ./
RUN npm install
COPY . .
CMD ["npm", "start"]
2
Answers
You could create a network between the to containers using –net look at this answer How to get Docker containers to talk to each other while running on my local host?
Another way, and my preferred way, is to use docker-compose and create networks between your containers.
EDIT ——-
Sorry, I didn’t see the notification of your question. This is not a video but to get started with the basics of docker-compose I would try something like https://docs.docker.com/compose/gettingstarted/ . For networking multiple containers together you can create simple networks like this https://accesto.com/blog/docker-networks-explained-part-2/.
Here is an example of one of the docker-compose.yml files we use.
Use Service Name and Port is always the best.
So if you have a docker file like the below you could use the URL http://client:5000