Docker nginx static website

Docker Nginx static website. How to use Docker to test a static website. I’m used Dockerfile to build and test as a local web development environment.

To create a directory for our Nginx Dockerfile

$ mkdir nginx
$ cd nginx
$ mkdir devopsroles
$ touch devopsroles/index.html
$ touch Dockerfile

The content our Dockerfile

FROM ubuntu:14.04
MAINTAINER PHAN VAN HUU <pvhuu90@gmail.com>, My blogs:devopsroles.com
RUN apt-get update
RUN apt-get -y -q install nginx
RUN mkdir -p /var/www/html/devopsroles
#ADD devopsroles/index.html /var/www/html/devopsroles/
ADD devopsroles.conf /etc/nginx/conf.d/
ADD nginx.conf /etc/nginx/nginx.conf
EXPOSE 80

The content of our devopsroles.conf file as below

server {
listen 0.0.0.0:80;
server_name _;
root /var/www/html/devopsroles;
index index.html index.htm;
access_log /var/log/nginx/default_access.log;
error_log /var/log/nginx/default_error.log;
}

File configure nginx.conf as below

user www-data;
worker_processes 4;
pid /run/nginx.pid;
daemon off;
events {
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
}

To create our index.html file as below:

$ cat devopsroles/index.html

The content as below:

<head>
<title>Test website</title>
</head>
<body>
<h1>Hello! My name HuuPV</h1>
</body>

Building our new Nginx image

$ sudo docker build -t devopsroles/nginx:v2 .
$ sudo docker run -d -p 8080:80 --name devopsroles -v /home/huupv/project/nginx/devopsroles:/var/www/html/devopsroles:ro devopsroles/nginx:v2 nginx

The result, Docker Nginx static website

To use docker images command as below:

$ sudo docker images

The output devopsroles container as below:

[sudo] password for huupv: 
REPOSITORY TAG IMAGE ID CREATED SIZE
devopsroles/nginx v2 8598ffebf6ae 10 minutes ago 305.1 MB

To use docker ps command as below:

$ sudo docker ps

The output below

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ebab6b61682b devopsroles/nginx:v2 "nginx" 8 minutes ago Up 8 minutes 0.0.0.0:8080->80/tcp devopsroles

To use curl command test docker Nginx static website

$ curl http://localhost:8080

Conclusion

To deploy simple static website use docker. Docker Nginx static website uses Dockerfile to build as the container. Thank you for reading the DevopsRoles page!

About HuuPV

My name is Huu. I love technology, especially Devops Skill such as Docker, vagrant, git, and so forth. I like open-sources, so I created DevopsRoles.com to share the knowledge I have acquired. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.