Reputation: 111
I have set up a fast-api docker container. I need to communicate with fast-api present in my docker container running locally through http requests, however I am not able to determine the IP address in which my fast-api docker container is running. My dockerfile is:
FROM jhonatans01/python-dlib-opencv
COPY . .
RUN pip3 install -r requirements.txt
CMD ["uvicorn", "main:app", "--reload"]
When I run fast-api locally by,
uvicorn main:app --reload
the terminal tells me where the instance is running. However docker does not provide any output. I have looked at http://192.168.99.100 and http://127.0.0.1 with no success.
Upvotes: 1
Views: 8367
Reputation: 109
Here is what worked for me to find IP address of the container:
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' your_container_id
Upvotes: 4
Reputation: 6616
While running the application with docker run
, you can pass an option called --network host
. This will run your application on 127.0.0.1
You will not need the container IP to access your application
But, if you want to know the container IP in any case you can do
docker ps
// to list all the docker containers
docker inspect <container_id>
// you will get container_id from the output of 1st command
This will give you a json including all information (and of course the IP)
Another solution :
As Kiaus's comment suggests ..
You can do port binding, means you have to pass option -p <port1>:<port2>
in the docker run
command
say, your python app is running on 8000
you can pass -p 7000:8000
and now your app will open on localhost:7000
Upvotes: -1