简体   繁体   中英

docker port exposing issue

I have a flask application that I'm trying to dockerize but the ports are not getting exposed properly.

DockerFile

FROM tiangolo/uwsgi-nginx-flask:python3.7

LABEL Name=testAPP Version=0.0.1
EXPOSE 5000

ADD . /app
WORKDIR /app

# Using pip:
RUN python3 -m pip install -r requirements.txt

ENTRYPOINT [ "python3" ]
CMD ["application.py" ,"runserver","-h 0.0.0.0"]

Docker Build is successful:

docker build --rm -f "Dockerfile" -t testAPP .

Docker Run is building the image successfully

docker run -device -expose 5000:5000 testAPP

Also tried,

docker run --rm -d -p 443:443/tcp -p 5000:5000/tcp -p 80:80/tcp testAPP

But when I try to access the site it throws an error

site can't be reached error

Flask App(Inside the APP)

if __name__ == '__main__':
    app.run(host='127.0.0.1', port=5000)

On Execution of the command

Docker container ps

CONTAINER ID     IMAGE        COMMAND      CREATED          STATUS    PORTS      NAMES
 8724cdb38e14    testAPP   "/entrypoint.sh pyth…" 15 seconds ago   Up 13 seconds    80/tcp, 443/tcp, 0.0.0.0:5000->5000/tcp  funny_galois

Defining a port as exposed doesn't publish the port by itself. Try with the flag -p , like:

-p container_port:local_port

example:

docker run -p 8080:8080 -v ~/Code/PYTHON/ttftt-recipes-manager:/app python_dev

But before running try to check if there is something else that already running on the specified port like:

lsof -i :PORTNUM 

and after with something like:

docker logs my_container

Make sure you're mapping your localhost port to the container's port

docker run -p 127.0.0.1:8000:8000 your_image

And once you're application is in the container, you want to run your app with the host set to 0.0.0.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM