norboten · cheat sheet

Inside a container, localhost is the container — cheat sheet

containers, networking
$ docker compose ps                                   # services, state, published ports
$ docker compose logs SERVICE                         # nginx's upstream errors name the address it tried
$ docker compose exec SERVICE wget -qO- http://api/   # test from inside a container
$ docker compose exec SERVICE getent hosts NAME       # does a name resolve in that container?
$ docker network ls; docker network inspect NET       # which containers are on which network
$ docker inspect C --format '{{range $k, $v := .NetworkSettings.Networks}}{{$k}} {{end}}'
$ docker inspect C --format '{{.HostConfig.RestartPolicy.Name}}'
$ docker compose config --quiet                       # validate the file
$ docker compose up -d --remove-orphans               # apply: recreate what changed
$ docker compose down                                 # stop and remove containers and project networks
$ docker run --rm --network NET -v ./x.conf:/etc/nginx/conf.d/default.conf:ro nginx:1.29-alpine nginx -t
services:
  web:
    ports: ["8088:80"]          # only the public service is published
    restart: unless-stopped
    depends_on: [api]
  api:
    restart: unless-stopped     # no ports: reachable as http://api:80 from web