Skip to main content

Docker Cheat Sheet

Common Commands and Use Cases

  • docker ps is used to show currently-running containers.
  • docker images is used to show locally available images, either downloaded or locally compiled.
    • docker rmi is used to delete local images.
      • docker rmi -f <image_id> the -f parameter is used to force delete images that might still be in use or have other dependent images.
    • docker system prune is used to purge unused, hanging, or cached images.
      • WARNING: docker system prune -a the -a parameter is used to remove ALL images.
  • docker compose or (for older versions) docker-compose is used along with a docker-compose.yml file to manage multiple services in concert.
    • docker compose up is used to start the services defined in the local docker-compose.yml file.
      • docker compose up -f docker-compose-foo.yml the -f parameter is used to denote a specific docker-compose file in the case that there are more than one or abnormally named files.
      • docker compose up -d the -d parameter is used to start the docker containers as daemons in the background.
      • docker compose up --build the --build parameter tells docker to rebuild all the service (images) in the docker-compose file.
    • docker compose down is used to stop all services defined in the local docker-compose.yml file.
    • docker compose build is used to build all services in the local docker-compose.yml file.

Tips

  • If you need to start, stop or build a single service (or subset of services) in a set of services defined in a docker-compose file, you can pass the names of the services after the docker compose command:
    • docker compose up servicename1 servicename2
    • docker compose down servicename1
    • docker compose build servicename3

Interacting with Containers

Some common use cases for interacting with containers might include:

  • Looking at logs inside the container.
  • Looking at files inside the container.
  • Running commands inside the container.
    • Django commands like createsuperuser.

Some common commands include:

  • Enter a bash session inside a container: docker exec -it <container_id> bash
  • Find a container's IP address: docker inspect <container_id> | grep IPA

Publishing Containers to a Registry/Repository

GQC uses Azure Container Registry (ACR) for publishing compiled images. For info on this process, visit General/Dev/Azure/Azure Container Registry