5 Building Image with Dockerfile

To build an image for your own app, first you need to prepare a file named as 'Dockerfile':

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

The first line (FROM) says that the image 'node' from the Docker public repository will be needed. You can also use a specific version by including a tag, eg.: FROM node:17-alpine

The second line (ENV) specifies the environment variables and their values.

The third line (RUN) tells Docker to first create the directory /home/app on the virtual file system of the container. There can be multiple RUN commands.

The fourth line (COPY) tells Docker to copy your app on the host to /home/app on the container virtual file system.

The last line (CMD) sets the entry point.




You are now ready to build the image for your own app:

docker build -t my-app:1.0 .

Then you can run the container for your app: