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.
Once we've got the Dockerfile, we can create a Docker image from it.
Now let us create the container from the image.
Let us browse localhost:8080, and we would be getting our Meditation App running.
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..