What instructions are used in Dockerfile?
sobes.tech AI
Answer from AI
FROM specifies the base image. RUN executes commands during the build. CMD sets the command to run when the container starts. ENTRYPOINT sets the executable when the container starts. COPY copies files from the host to the image. ADD copies files from the host or URL into the image and can unpack archives. WORKDIR sets the working directory. ENV sets environment variables. ARG defines build-time variables. VOLUME mounts a volume. EXPOSE indicates the ports the container listens on. USER sets the user to run commands. LABEL adds metadata to the image. HEALTHCHECK checks the container's health. SHELL sets the shell for RUN, CMD, and ENTRYPOINT commands. STOPSIGNAL sets the system call to send to the container to stop it. ONBUILD adds a trigger instruction that runs when the image is used as a base.
Example usage:
# Use Ubuntu as the base image
FROM ubuntu:22.04
# Install packages
RUN apt-get update && \
apt-get install -y nginx
# Copy Nginx configuration file
COPY nginx.conf /etc/nginx/nginx.conf
# Expose port 80
EXPOSE 80
# Run Nginx when the container starts
CMD ["nginx", "-g", "daemon off;"]