Docker: Making Containers Publicly Available

Updated: Jan 18

In this tutorial, you'll learn how to make an application run inside a container accessible outside of the Docker host server(publicly Available). Additionally, you will learn how to share data between containers and their Docker host server. I will do all the command examples using Nginx, a web server that can also be used as a reverse proxy, load balancer, mail proxy, and HTTP cache.

If you want to find the run command for Exposing external port, you can navigate to the Docker site at this address: and there you will find the exact syntax for it:

let's run it with a few changes:

PS C:\system32> docker run --name nginxWeb -d -p 8080:80 nginx

So, in this line of code, we created a new Nginx container with a specific name, "nginxWeb." Also, we opened an external port to the web '8080', which will re-direct network traffic to and from it to the TCP port inside the Nginx container (8080 - Outside world, 80 - The inside world of the container).

Now, let's ensure that the new container is up and running with port 8080:

Now we can access this container using the http://localhost:8080 address:

And if we want to access this address from a remote machine that is not related to our network, we will first have to find the IP address of the Docker Host. I'm using a Windows server, so I can see the Virtual network of the server very quickly by just running the IPconfig command:

So now I can use the following address to access this container from anywhere.

To track the access logs of our container, which are generated per requests to access the container, we will use the Docker log command:

docker logs nginxWeb

Now let's go and stop our container using the Docker Stop command. This is for adding some HTML content to change the default Nginx message. Here are a few code lines that you need to run:

PS C:\> cd webpage
PS C:\webpage> echo 'Hi from daivd Tzemach' > index.html 
PS C:\webpage> cd..
PS C:\> docker run -p 8081:80 --name nginxcontainer3 -v ${PWD}/webpages:/usr/share/nginx/html:ro -d nginx

Now let's add some information about the syntax I used here:

${PWD} - Provide the current working directory, we can look at its content by running the echo command:

-V option - Creating a volume for sharing files, the syntax I used is -v followed by the path on the host machine you want the container to have access to, followed by a colon, and then where you want that data to be accessed from inside the container (in this example I used the 'ro' which mends read-only, meaning that the volume will be accessible only for read and cannot be edited, and can only be changed in the docker host itself). So in this example, ${PWD}/webpages from a docker host machine is available in share/Nginx/HTML inside the container (it maps it from the docker host into the container ).

And now let's check if it worked for us using the 8081:80 address:

6 views0 comments

Recent Posts

See All