Docker Cheat Sheet
Common Commands and Use Cases
docker psis used to show currently-running containers.docker imagesis used to show locally available images, either downloaded or locally compiled.docker rmiis 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 pruneis used to purge unused, hanging, or cached images.- WARNING:
docker system prune -athe -a parameter is used to remove ALL images.
- WARNING:
docker composeor (for older versions)docker-composeis used along with a docker-compose.yml file to manage multiple services in concert.docker compose upis used to start the services defined in the local docker-compose.yml file.docker compose up -f docker-compose-foo.ymlthe -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 -dthe -d parameter is used to start the docker containers as daemons in the background.docker compose up --buildthe --build parameter tells docker to rebuild all the service (images) in the docker-compose file.
docker compose downis used to stop all services defined in the local docker-compose.yml file.docker compose buildis 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 servicename2docker compose down servicename1docker 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