podman buildFROMRUNCOPYUSERCMD / ENTRYPOINT| Base Image | Use It When |
|---|---|
ubi8/ubi-minimal / ubi9/ubi-minimal | You want a small base with microdnf |
ubi9/ubi | You need full dnf and common tools |
Language images, such as ubi9/python-311 | The runtime your app needs is known |
| Instruction | Purpose |
|---|---|
FROM | Sets the base image |
RUN | Runs a command at build time, committing the result as a layer |
COPY / ADD | Copies files from the build context into the image |
ENV | Sets an environment variable for build and run time |
EXPOSE | Documents the port(s) the app listens on |
USER | Sets the user the process runs as |
CMD | The default command at start; can be overridden |
ENTRYPOINT | A fixed executable; CMD supplies its default arguments |
ENTRYPOINT ["ping"] CMD ["-c", "3", "localhost"]
$ podman run myping # runs: ping -c 3 localhost $ podman run myping -c 1 example.com # runs: ping -c 1 example.com
Arguments after the image name replace CMD, but the ENTRYPOINT stays. With only CMD, they replace the whole command.
# Containerfile
FROM registry.access.redhat.com/ubi8/ubi-minimal
RUN microdnf install -y httpd && microdnf clean all && \
sed -i 's/^Listen 80$/Listen 8080/' /etc/httpd/conf/httpd.conf && \
chgrp -R 0 /var/log/httpd /run/httpd && \
chmod -R g=u /var/log/httpd /run/httpd
COPY ./site/ /var/www/html/
EXPOSE 8080
USER 1001
CMD ["httpd", "-D", "FOREGROUND"]
sed, chgrp, and chmod steps fix both.$ podman build -t quay.io/myorg/mysite:1.0 . $ podman run -d --name mysite -p 8080:8080 quay.io/myorg/mysite:1.0
-t names and tags the image.. is the build context: the directory whose files COPY can use.Containerfile or Dockerfile.Podman reuses a cached layer until an instruction, or a file it copies, changes. Every layer after that is rebuilt.
# Slow: any code change re-runs the package install COPY ./site/ /var/www/html/ RUN microdnf install -y httpd # Fast: packages are cached; only the COPY layer rebuilds RUN microdnf install -y httpd COPY ./site/ /var/www/html/
USER instruction, the container runs as root. Set a non-root USER unless root is truly needed.CMD and ENTRYPOINT?USER instruction, and why?