Create a Dockerfile

Create a Dockerfile

To build a Docker container, we need to create a Dockerfile that describes our image build process.

There are many ways to create a Dockerfile. The simplest and most effective for a Node.js application is to extend one of the official Node containers.

We are here extending the node:alpine container, which is the lightest possible version of the node engine.

Create a Dockerfile with the following content

FROM node:alpine

WORKDIR /usr/demo-csv-writer
COPY ./package.json  ./
COPY ./package-lock.json  ./
RUN npm install

COPY ./index.mjs  ./.

CMD ["npm", "start"]

And execute

docker build -t <your dockerhub username>/demo-csv-writer .

As a best practice, you should always create a .dockerignore file containing the list of files not needed by Docker during the image creation.

In this case, your .dockerignore file should contain the following text.


Great job

You just built your first IOhubTM application. Once it is published, we can use it in IOhubTM like other existing containers.

You can find the complete demo project on Github here.

If you need help to build and publish your image, you can follow the basic Docker documentation for IOhubTM here.