Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDenis Frunz
15,929 PointsDocker file EXPOSE port
Hi fellows,
Currently, I learn Docker by watching videos.During these videos the teacher run containers docker run -p 5000:5000 {image} as was said I have to expose a port ,but I found out that I can add EXPOSE 5000 to Dockerfile however I still must provide -p command and port to be able to connect to my flask app.What's more docker container runs with flask and shows which host and port I have to connect when I do that I fail and it runs only when I explicitly run -p argument and which port I want to expose.So EXPOSE command in Dockerfile doesn't work as I expected or I miss smth. Thank you.
1 Answer
adrian miranda
13,561 PointsThe EXPOSE 8080
in your Docker file exposes it on the container, which is difficult to connect to directly. The -p argument on docker run, says that when you connect to particular port on your local system, you will be connected to a particular port on the container.
So, yes, you will almost always want both (or something similar, anyway).
Denis Frunz
15,929 PointsDenis Frunz
15,929 Points''
Base image
FROM python:3.7.2-alpine
Working directory
WORKDIR /usr/src/app
add and install requirements
COPY ./requirements.txt /usr/src/app/requirements.txt RUN pip install -r requirements.txt
add app
COPY . /usr/src/app
Make port available
EXPOSE 8080
ENTRYPOINT [ "python3" ]
Command to run when the container starts
CMD ["app.py"] '''