How to access Flask API running on localhost docker container?
I created miniconda docker image with Flask API on it.
Dockerfile is:
FROM continuumio/miniconda3
# Install base utilities
RUN apt-get update \
&& apt-get install -y wget \
&& rm -rf /var/lib/apt/lists/*
COPY api /root/api
RUN echo "Running $(conda --version)"
RUN conda update conda
RUN conda create -n api python=3.9
RUN echo "conda activate api" >> ~/.bashrc
SHELL ["/bin/bash", "--login", "-c"]
RUN conda activate api
RUN conda install flask requests
ENTRYPOINT ["conda", "run", "-n", "api", "python", "/root/api/main.py"]
Flask API uses port 5000. I've tried to add EXPOSE 5000
to dockerfile, but I didn't find any difference.
It builds without error, but I'm still not sure everything is correct. So I run it locally on my PC to test. But I can't access it. I've tested http://172.17.0.2/api
and http://localhost/api
, but it didn't respond. Also I've tried to run main.py
in container terminal, but it says "Port 5000 is in use by another program".
So here is what I would like to ask:
- How to properly run Flask API on Linux? Am I doing it right?
- How to properly run Flask API in Docker? Am I doing it right?
- How to access Flask API running on localhost Docker container (same PC)? I just can't understand what ip/address my API gets.