In this article, we will cover basic steps involved in running a web application as a docker container.
Let’s start by taking baby-steps. First, we’ll use Docker to run a static website in a container. The website is based on an existing image. We’ll pull a Docker image from Docker Store, run the container, and see how easy it is to set up a web server.
The image that you are going to use is a single-page website that was already created for this demo and is available on the Docker Store as docker/welcome-to-docker
You can download and run the image directly in one go using docker run
as follows.
$ docker run -d -p 8088:80 --name welcome-to-docker docker/welcome-to-docker
-d
will create a container with the process detached from our terminal-P
will publish all the exposed container ports to random ports on the Docker host--name
allows you to specify a container name
So, what happens when you run this command?
Since the image doesn’t exist on your Docker host, the Docker daemon first fetches it from the registry and then runs it as a container.
Now that the server is running, do you see the website? What port is it running on? And more importantly, how do you access the container directly from our host machine?
Let’s run the command with some new flags to publish ports and pass your name to the container to customize the message displayed. We’ll use the -d option to run the container in detached mode.
Docker Run:
Docker Inspect the Application:
Lets launch the Docker container Application
Open http://localhost:8088
in your browser to see the app running.