Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dockerfile and changed personal message #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

omkar-ti
Copy link
Owner

No description provided.

Dockerfile Outdated

# Run FastAPI server on the port exposed above.
CMD uvicorn main:app

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to specify the host address here (reason).

Also, you should prefer the array-based syntax for CMD over the string-based syntax (more info here).

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made the said changes.
I should have cleared this earlier but,
if I run the docker image normally
docker run myimage
the application starts, however I can't access it, it says port not exposed

if I run the docker image like this
docker run -p 8000:8000 myimage

the application starts fine and I can access it

but if I create an image without the EXPOSE 8000 line in dockerfile and run with the -p label, the application still starts and is accessible

Am I missing something?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason you need to specify -p is because you need to publish ports of your container when running it from a Docker image, in order to have them be accessible from the outside world.
Take a look at this link for more info: https://docs.docker.com/config/containers/container-networking/#published-ports

As for why it still works without the EXPOSE 8000 line, the EXPOSE command doesn't actually do anything other than serving as documentation between the person writing the Dockerfile, and the person running a container from that Dockerfile. If you see EXPOSE <port_no> in a Dockerfile, it indicates that you should include -p <port_num>:<port_num> when running a container from an image from that Dockerfile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants