Skip to content

Images

Terminal window
docker pull nginx:1.27 # download an image
docker images # list local images
docker image inspect nginx:1.27 # full metadata (JSON)
docker image history nginx:1.27 # layers and their sizes

A minimal Dockerfile (Podman also reads it as Containerfile):

FROM python:3.13-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["python", "app.py"]
Terminal window
docker build -t myapp:1.0 . # build from the Dockerfile in the current directory
docker build -t myapp:1.0 -f other.Dockerfile .

The . at the end is the build context: the folder whose files COPY can see. Add a .dockerignore (same syntax as .gitignore) to keep node_modules, .git or secrets out of it.

Tips for smaller, faster builds:

  • Copy the dependency files and install them before copying the rest of the code, so that layer is cached while you only change code.
  • Use -slim or -alpine base images.
  • Combine related RUN steps and clean caches in the same step.
Terminal window
docker tag myapp:1.0 ghcr.io/myuser/myapp:1.0
docker login ghcr.io
docker push ghcr.io/myuser/myapp:1.0
Terminal window
docker rmi myapp:1.0 # remove an image (fails if a container still uses it)
docker image prune # remove dangling images (untagged leftovers of old builds)
docker image prune -a # remove every image not used by any container