Sample : template of docker file

 # Use an official base image
FROM ubuntu:20.04

# Set environment variables
ENV MY_ENV_VARIABLE=value

# Set the working directory inside the container
WORKDIR /app

# Copy files from the build context to the container
COPY . /app

# Install dependencies
RUN apt-get update && apt-get install -y package1 package2

# Expose a port to listen on
EXPOSE 8080

# Specify a default command (can be overridden at runtime)
CMD ["executable", "arg1", "arg2"]

# Set the entry point for the container (overrides CMD)
ENTRYPOINT ["executable"]

# Define a volume for data persistence
VOLUME /data

# Label the image with metadata
LABEL maintainer="your.name@example.com" version="1.0"

# Add metadata to an image
ADD file.tar.gz /data

# Specify a user to run the container
USER appuser

# Healthcheck to monitor container health
HEALTHCHECK --interval=30s --timeout=5s CMD curl -f http://localhost/ || exit 1

# Set stop signal
STOPSIGNAL SIGTERM

# Specify the user who will run the container
USER appuser

# Define an argument
ARG build_arg=value

# Execute a command during build
RUN echo "Build argument is: $build_arg"

# Mark the image as a trusted build
ONBUILD ADD . /app

# Multistage build
FROM builder as intermediate
COPY . /app

# Final stage
FROM ubuntu:20.04
COPY --from=intermediate /app /app

Comments

Popular posts from this blog

Docker Introduction