Docker File Instructions
Dockerfile is a script that contains instructions for building a Docker image. Here are some common instructions used in Dockerfile:
- FROM: specifies the base image to use for the build process.
- RUN: executes a command in the container. This command is executed during the build process.
- COPY/ADD: copies files or directories from the host machine to the container.
- WORKDIR: sets the working directory for the rest of the instructions in the Dockerfile.
- ENV: sets an environment variable in the container.
- EXPOSE: specifies the port(s) that the container will listen on at runtime.
- CMD/ENTRYPOINT: specifies the command to run when the container starts.
Here is an example Dockerfile that uses some of these instructions:
# Use the official Node.js image as the base image FROM node:14 # Set the working directory to /app WORKDIR /app # Copy the package.json and package-lock.json files to the container COPY package*.json ./ # Install the dependencies RUN npm install # Copy the rest of the application files to the container COPY . . # Expose port 3000 EXPOSE 3000 # Start the application when the container starts CMD [ "npm", "start" ]
Dockerfile uses Node.js as the base image, sets working directory to /app, copies package.json, package-lock.json, installs the dependencies, copies the rest of the application files, exposes port 3000, and starts the application when the container starts.
