How to build a hello world docker image by docker file
First, create a `hello-world.js’ file
1 | console.log("Hello World") |
Then, create a Dockerfile in the same directory, the Dockerfile should look like that:
1 | FROM ubuntu |
FROM ubuntu means we ubuntu the ubuntu image as the base
RUN apt update && apt install nodejs -y means install nodejs into the ubuntu image
WORKDIR is used to define the working directory of a Docker container.
COPY . . is to copy the current directory(the hello-world.js) to the WORKDIR
CMD ["node", "/app/hello-would.js"] is the command to run after the image load.
Finally, Build the image
docker build -t {image name and version} .
-t is the tag for the image name and version, for example, etklam/hello_app:0.1
. is the Dockerfile directory