How to Run a Web Server from a Docker Container? Yes, I Know IT ! Ep 16
Articles,  Blog

How to Run a Web Server from a Docker Container? Yes, I Know IT ! Ep 16

Docker, Images, Containers… all that to run an HTTP server? Seems complicated, isn’t it? In a previous video, we’ve installed Docker. Today, you will start playing with a couple
of containers in order to gain a better understanding of the concepts behind Docker. And for that, we will see how to run an Apache
HTTP web server from a container. The first step is to search if we can find
a readily available image for the software we need. By searching on the Docker hub I found that official image, we can download using the “docker pull” command: At this point, you have the docker image for
the Apache HTTP server on your system. But an image is just a blueprint. To run the Apache server, you have to create
a container from that image: Ands a matter of fact, you can create as many
containers as you want from the same image: Let’s now start a couple of them: Even if they were created from the same image,
the two containers are now independent entities. For example, let’s see what happens if I create
a new file in one of them: As you can see, the file only exists in the
container it was created. And obviously, I can create a file with the
same name in the second container — that will not interfere … in any way … with
the other one: Ok, using the bash is nice, but we’ve installed
HTTP servers. So it would be better if you could access
those files using your web browser. For that, we need the IP address of the containers. Provided the necessary tools are available,
we can query the IP address directly from the container, just like if it was a real
computer: But, as a more generic solution, I prefer
using the docker inspect command to obtain that piece of information: By the way, you can notice the two containers
have different IP addresses. As well as two different MAC addresses. Confirming there are seen as two different
hosts. And since we have now the containers IP addresses,
and since docker has taken care for you of the low-level networking details, you can
access those servers from your web browser: To continue this rapid tour of the basic docker
commands, let’s see how you can stop one of those containers: Now, the container is stopped. That means the corresponding web server is
stopped. And we can check it is no longer accessible: Finally, when you no longer need a container,
just remove it: But beware, the data stored in that container
will be lost. As we’ve seen, you can start and stop a container
in a matter of seconds. This is a great strength of that technology. I encourage you to practice a little bit with
containers based on the Apache HTTP docker image. For example, you can try to create several
containers and then modify the index.html file in each of them to see what appends when
you load the corresponding pages in your browser. And once you’ll be more comfortable with the
basic docker commands, it will be time for you to take my challenge. We used Apache HTTP web server in this video. But this is not the only HTTP server available
out there. “Lighty” is another popular choice. So, I would like you to start a “Lighty” container
and perform the necessary changes … …so we can see THAT when your web browser
is pointed to the container IP address: As of myself, I’m looking forward to reading
your solution in the comment section below!


Leave a Reply

Your email address will not be published. Required fields are marked *