Run a simple webpage using docker

Docker is a container technology that helps easier application deployment by providing an abstraction over Linux OS. In this tutorial, I will go through creating a simple (simplest) docker container and deploy a very basic web-page that runs on port 3000.

To install docker run sudo apt-get install (in ubuntu). You might have to restart the OS after the installation.

1. Dockerfile

To create a docker file (configuration file used by docker to create a docker image). Run following commands.

$ mkdir docker-example
$ cd docker-example
$ gedit Dockerfile

Add following text into the file.

FROM ubuntu:14.04

USER root
RUN apt-get update && apt-get install -y \
    python3 \
    curl && \
    rm -rf /var/lib/apt/lists/*
RUN groupadd -r nonroot && \
    useradd -r -g nonroot -d /home/nonroot -s /sbin/nologin -c "Nonroot User" nonroot && \
    mkdir /home/nonroot && \
    chown -R nonroot:nonroot /home/nonroot

USER nonroot
WORKDIR /home/nonroot/
RUN curl -o index.html

USER nonroot
WORKDIR /home/nonroot/
CMD ["python3", "-m", "http.server", "3000"]

Edit the apt-get section to add packages you need to run your application. The next block of code downloads a web page to host inside /home/nonroot/ directory. The final block of code runs python’s SimpleHTTPServer to host the directory containing the file.

2. Build docker image.

$ sudo docker build -t=docker-example .

Successfully built <image-id>

3. Run docker image

$ sudo docker run -p 3000:3000 -i -t docker-example

Browse http://localhost:3000/ to view the webpage.



After this installation, you should be able to modify this tutorial to bundle your application specific packages and distribute your application without conflicting with dependencies. You can publish your package to for easier lookup and installation.






Filed under Uncategorized

2 responses to “Run a simple webpage using docker

  1. Unfortunately I followed all steps and it still failed with this error: The command ‘/bin/sh -c apt-get update && apt-get install -y python3 curl && git nginx nodejs rm -rf /var/lib/apt/lists/*’ returned a non-zero code: 127

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s