Skip to content

Ayush30/DailyLearningApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

FastAPI Docker Guide

Docker Commands

1. Build Docker Image

docker build -t fastapi .

Usage: Builds a Docker image named fastapi from the Dockerfile in the current directory. The -t flag tags the image with the specified name.

2. Clean Up System Resources

docker system prune -a

Usage: Removes all unused containers, networks, images, and optionally volumes. The -a flag removes all dangling and unused images. Use with caution as it frees up disk space.

3. List All Containers

docker ps -a

Usage: Lists all containers (running and stopped). Without -a, only running containers are shown.

4. Run Container Interactively

docker run --rm -it -p 8000:8000 fastapi bash

Usage:

  • --rm: Automatically removes the container when it exits
  • -it: Interactive terminal (combines -i for stdin and -t for terminal)
  • -p 8000:8000: Maps port 8000 from container to host
  • Starts a bash shell inside the fastapi container for debugging

5. Remove Docker Image

docker rmi fastapi

Usage: Removes the Docker image named fastapi. Make sure no containers are using this image before deletion.

6. Build Image (Alternative)

build -t fastapi .

Usage: Shorthand for building the image (note: typically requires docker prefix).

7. List All Docker Images

docker images

Usage: Displays all Docker images on your system with their repository, tag, image ID, creation time, and size.

8. Remove All Images

docker rmi $(docker images -q) -f

Usage:

  • docker images -q: Lists all image IDs
  • docker rmi: Removes images
  • -f: Force remove even if images are in use
  • Combined: Removes all Docker images forcefully. Use with caution.

9. Start Services with Docker Compose

docker compose up

Usage: Starts and runs all services defined in docker-compose.yml. Containers run in the foreground. Press Ctrl+C to stop.

10. Build and Start Services with Docker Compose

docker compose up --build

Usage: Rebuilds Docker images before starting services. Useful when you've made changes to the Dockerfile or code. Ensures services run with the latest builds.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors