Docker Commands
The Docker commands provide an easy way to manage Docker containers for your FastAPI project.
Basic Usage
This will build and start your Docker containers defined in your project's docker-compose.yml file.
Available Commands
Command | Description |
---|---|
build |
Build Docker containers |
run |
Start Docker containers |
down |
Stop and remove Docker containers |
cmd "command" |
Run any Docker Compose command |
Command Details
Build
Builds the Docker containers defined in your project's docker-compose.yml file.
This command will:
- Check if a
.env
file exists and create one fromenv.txt
if needed - Build all containers defined in
docker/compose/docker-compose.yml
Run
Starts the Docker containers in detached mode.
This command will:
- Start all containers defined in
docker/compose/docker-compose.yml
- Run in detached mode (
-d
flag) - Set up necessary networking
Down
Stops and removes running Docker containers.
Options:
Option | Short | Description |
---|---|---|
--volumes |
-v |
Also remove volumes |
Example to remove containers and volumes:
Cmd
Runs any arbitrary docker-compose command.
Examples:
fastapi-admin docker cmd "ps"
fastapi-admin docker cmd "logs api"
fastapi-admin docker cmd "restart api"
Integration with Project
The Docker commands are designed to work with the project structure created by the startproject
command. The commands expect:
- A
docker/compose/docker-compose.yml
file in your project - A compatible Dockerfile that defines your API service
- PostgreSQL database service configuration
Common Issues
- Docker not installed: Ensure Docker and docker-compose are installed and running
- Port conflicts: If ports are already in use, update the port mappings in your docker-compose.yml
- Permission issues: On Linux/Mac systems, you might need to run with sudo or add your user to the docker group
- Environment variables: If the container fails to start, check your
.env
file for missing required variables - Resource limitations: Ensure Docker has sufficient CPU/memory allocated (especially on Docker Desktop)
Troubleshooting
If you encounter issues with Docker commands:
- Check Docker logs:
fastapi-admin docker cmd "logs"
- Verify all containers are running:
fastapi-admin docker cmd "ps"
- Ensure your
.env
file has all required environment variables - Try rebuilding the containers:
fastapi-admin docker build
- Check connectivity between containers with:
fastapi-admin docker cmd "exec api ping postgres"
For more advanced Docker issues, refer to the Docker and docker-compose documentation.