Creating an image for Nginx

Here we will create a minimalist Docker Nginx image, displaying the message Helloworld !.

First, let’s create the Dockerfile based on the image nginx:alpine:

cat <<EOF> Dockerfile
FROM nginx:alpine
ADD www.conf /etc/nginx/conf.d/
ADD index.html /usr/share/nginx/html/

Next, let’s create the file index.html:

cat <<EOF> index.html
<p>Helloworld !</p>

Now, let’s create a minimalist Nginx configuration file:

cat <<EOF> www.conf
server {
    listen 80;
    root /usr/share/nginx/html;

Let’s create the Docker nginx-helloworld image:

docker build -t nginx-helloworld .
Sending build context to Docker daemon  28.04MB
Step 1/3 : FROM nginx:alpine
alpine: Pulling from library/nginx

0c94c7c5: Already exists 
2de6f957: Pulling fs layer 
e8e54998: Pulling fs layer 
206a393c: Pulling fs layer 
Digest: sha256:9b22bb6d703d52b079ae4262081f3b850009e80cd2fc53cdcb8795f3a7b452ee
Status: Downloaded newer image for nginx:alpine
 ---> e5dcd7aa4b5e
Step 2/3 : ADD www.conf /etc/nginx/conf.d/
 ---> 79f1a2d79eb4
Step 3/3 : ADD index.html /usr/share/nginx/html/
 ---> b224ba239a06
Successfully built b224ba239a06
Successfully tagged nginx-helloworld:latest

Let’s launch the nginx server:

docker run -d -p 80:80 nginx-helloworld

Let’s check that the web server responds:

curl http://localhost
<p>Helloworld !</p>


Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now