Docker Chapter 5: Hosting Meditation App with Dockerfile

Docker Chapter 5: Hosting Meditation App with Dockerfile

In this article, we will deploy a meditation app (written in HTML and JavaScript) in the Nginx server using Dockerfile. Dockerfile is a simple text file which is consists of instructions to create an image. The Dockerfile does not have any extension and is case-sensitive. Let us go through a sample Dockerfile.

FROM node
ENV MONGO_DB_USERNAME=admin \
    MONGO_DB_PWD=password
RUN mkdir -p /home/app
COPY . /home/app
CMD ["node", “server.js”]

Each instruction creates one layer on top of the previous one.

FROM creates a layer from node Docker Image, if the version is not defined it will pick up the latest one. (Node - Official Image | Docker Hub). To define a version use FROM node:version

ENV creates environment variables. It takes input as key-value pair.

RUN is an image-building step, here it's making a directory /home/app. A Dockerfile can contain multiple RUN steps that are layered on top of each other to form an image.

COPY adds files from your Docker client’s current directory.

CMD is the command to execute in your container. As its a node application, here in the command running node server.js

There are some other operations available, such as EXPOSE, WORKDIR, VOLUME, ENTRYPOINT, LABEL, MAINTAINER

Now let's host Meditation App, link: GitHub - kunal-kushwaha/MeditationApp Once we've cloned the app from GitHub, create a file Dockerfile with instructions to create an image.

1641480527292-185199.png

Once we've got the Dockerfile, we can create a Docker image from it.

1641480706585-851936.png

Now let us create the container from the image.

1641480862422-347101.png

Let us browse localhost:8080, and we would be getting our Meditation App running.

1641480954920-917187.png

This is how you can host any kind of application in the container. Below Dockerfile is an example to host python code.

FROM ubuntu:18.04
COPY . /app
RUN make /app
CMD python /app/app.py

This is the last article in the series of Docker, to read previous chapters in this series follow the below links.

pawanadubey.hashnode.dev/docker-chapter-1-i.. pawanadubey.hashnode.dev/docker-chapter-2-w.. pawanadubey.hashnode.dev/docker-chapter-3-m.. pawanadubey.hashnode.dev/docker-chapter-4-d..

Did you find this article valuable?

Support Pawan Dubey's Blog by becoming a sponsor. Any amount is appreciated!