ports: Publishes container ports to the host, mapping HOST:CONTAINER. The Compose equivalent of docker run -p. In Docker Compose, ports publishes container ports on the host, written as "8080:80", host port first. It is the Compose version of docker run -p. Services that only need to talk to each other do not need published ports at all. Inside the Compose network, the app reaches the database at mysql:3306 without any mapping. Publish ports only for what you need to reach from your own machine or the outside world.
Quote port mappings in YAML, because unquoted values like 22:22 can be read as numbers in base 60 by some YAML parsers. On shared or public servers, bind to localhost, such as "127.0.0.1:8080:80", and put a reverse proxy in front for public traffic. That keeps databases and admin tools off the internet.
Use this skill when setting up, initializing, or Dockerizing a project, even if the user doesn't explicitly mention Docker but describes a need for containerized local development, adding a database or cache dependency, or running services without host-level installs. Covers Dockerfile, compose.yaml, and .dockerignore creation with Docker best practices.
Use this skill when creating, modifying, or debugging Docker Compose configurations, even if the user just says they need to wire services together, add a database to their stack, or set up a local development environment with multiple containers. Covers service definitions, health checks, dependency ordering, volumes, networks, environment variables, and development overrides.
Use this skill when writing, reviewing, or optimizing Dockerfiles, even if the user just says their image is too large, their build is slow, or they need to harden a container for production. Covers multi-stage builds, layer caching, .dockerignore, non-root users, and image size optimization.