Sobes.tech
Junior — Middle

Can you explain the differences between ENV and COPY commands in Dockerfile and their purpose?

sobes.tech AI

Answer from AI

The ENV command in a Dockerfile is used to set environment variables inside the container. These variables are available during container runtime and can influence the behavior of applications or scripts.

The COPY command is used to copy files or directories from the host (where the image is built) into the container image. This allows adding necessary files, such as source code, configurations, or scripts.

Example:

FROM ubuntu:20.04
ENV APP_ENV=production
COPY ./app /usr/src/app

Here, APP_ENV is an environment variable, and the contents of the app folder are copied into the image.

In summary:

  • ENV sets environment variables.
  • COPY copies files into the image.