
If you do not pass a tag, Docker will use “latest” as its default tag. We’ll leave off the optional “tag” for now to help simplify things. The tag is used to set the name of the image and an optional tag in the format ‘name:tag’. The build command optionally takes a -tag flag. The Docker build process can access any of the files located in the context. A build’s context is the set of files located in the specified PATH or URL. The docker build command builds Docker images from a Dockerfile and a “context”. To do this, we use the docker build command. Now that we’ve created our Dockerfile, let’s build our image. dockerignore file and add the node_modules directory in it: node_modules To improve the build’s performance,Ĭreate a. dockerignore file lets you specify files and directories dockerignore fileĭockerfile refers to the file specified in an instruction, for example, aĬOPY instruction. # syntax=docker/dockerfile:1 FROM node:18-alpine ENV NODE_ENV=production WORKDIR /app COPY RUN npm install -production COPY. One of the simplest things you can do to improve performance is to set NODE_ENV to production. The NODE_ENV environment variable specifies the environment in which an application is running (usually, development or production). If you want to learn more about creating your own base images, see Creating base images. In the same way, when we use the FROM command, we tell Docker to include in our image all the functionality from the node:18-alpine image.

This would create a class called MyImage that inherited functionality from the base class NodeBaseImage. For example, if we were able to create Docker images in JavaScript, we might write something like the following. You can think of this in the same way you would think about class inheritance in object oriented programming. Therefore, instead of creating our own base image, we’ll use the official Node.js image that already has all the tools and packages that we need to run a Node.js application. # syntax=docker/dockerfile:1 FROM node:18-alpineĭocker images can be inherited from other images. Create a directory in your local machine named node-docker and follow the steps below to create a simple REST API. Let’s create a simple Node.js application that we can use as our example.

Now that we have a good overview of containers and the Docker platform, let’s take a look at building our first image. You’re familiar with the Dockerfile format.
