Reputation: 92
Say I have mywebsite.com pointing to my Ubuntu server.
There is a docker container running on my Ubuntu server.
Is it possible to direct requests to my Ubuntu server to the application being exposed by the docker container?
I'm not entire sure what to search for this question. I'd imagine I'd have to setup nginx as a proxy or something?
I understand there maybe better server setups, I'm wondering if this particular one is possible.
Upvotes: 1
Views: 313
Reputation: 3662
Yes, it is possible. You need:
As an example, you can use Apache for this.
With a simple Dockerfile:
FROM httpd:2.4
RUN echo "<h1>It works!</h1>" > /usr/local/apache2/htdocs/index.html
And commands:
# Builds my Dockerfile above and tags the image as "test"
docker build . -t test
# Creates a container with the default command running, which
# starts Apache. Publishes (-p) port 80 inside the container and
# binds it to port 80 on the host machine
docker run --rm -p 80:80 test
If you run this locally (see all caveats above) you can visit http://localhost
and see the message above. The key is the -p
flag, which publishes port 80.
https://docs.docker.com/engine/reference/commandline/run/
There are a number of uses for nginx. You can use nginx as the application doing the listening to render/serve static pages. You can also use nginx as a proxy between the client machine (web browser, etc.) and another running process (in another container or another server). If you provided additional detail about what you're actually trying to accomplish I might be able to point you in the right direction.
Upvotes: 1