Javad Zahrabi

Docker

Container build + run. Daily-driver commands; Compose has its own group.

Official docs

Images

  • docker build -t my-app:1.0 .

    Build from the Dockerfile in the current directory and tag the result.

  • docker images

    List local images.

  • docker pull nginx:1.27

    Pull an image from a registry without running it.

  • docker tag my-app:1.0 registry.io/me/my-app:1.0

    Add another tag (e.g. before a push).

  • docker push registry.io/me/my-app:1.0

    Push a tagged image to its registry.

  • docker rmi my-app:1.0

    Delete a local image.

Containers

  • docker run --rm -it nginx:1.27

    Run a container in the foreground; remove on exit; allocate a TTY.

  • docker run -d -p 8080:80 --name web nginx:1.27

    Detached, port-forwarded, named.

  • docker ps

    List running containers. -a for stopped too.

  • docker logs -f web

    Stream logs from a container.

  • docker exec -it web sh

    Get an interactive shell inside a running container.

  • docker stop web && docker rm web

    Stop and remove a container.

Compose

  • docker compose up -d

    Start every service defined in docker-compose.yml in the background.

  • docker compose down

    Stop + remove containers, networks. Add -v to also remove volumes.

  • docker compose ps

    Status of services in this compose project.

  • docker compose logs -f web

    Follow logs from one service.

  • docker compose build --no-cache

    Rebuild service images from scratch.

Networks & volumes

  • docker network ls

    List networks.

  • docker network create app-net

    Create a user-defined bridge so containers can resolve each other by name.

  • docker volume ls

    List volumes.

  • docker volume create pgdata

    Create a named volume.

  • docker volume inspect pgdata

    Show mount point and metadata.

Housekeeping

  • docker system df

    How much disk are images / containers / volumes using?

  • docker system prune

    Delete stopped containers + dangling images + unused networks. Add --volumes to also wipe unused volumes.

  • docker image prune -a

    Aggressively remove unreferenced images. Be careful in shared environments.

  • docker login registry.io

    Auth against a registry — required before push.