container DNS: Docker runs an embedded DNS server on user-defined networks so containers resolve each other by name or alias. On a user-defined Docker network, Docker runs a small DNS server so containers can find each other by name. From the web container, the hostname db resolves to the database container's current IP address.
This is why Docker Compose files can use DB_HOST=db instead of IP addresses, which change whenever a container is recreated. You can also add aliases so a container answers to more than one name.
What should you keep in mind with container DNS?
Name resolution only works on user-defined networks, not on Docker's default bridge. Compose creates one for you. If ping db fails, check that both containers are on the same network with docker network inspect. And remember that service names are not reachable from your own computer's browser; for that you need a published port.
What does an example of container DNS look like?
# from the "web" container, on a shared network: ping db curl http://db:5432
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.