Deployment
After the Docker images are loaded and the application is deployed using docker compose
, it is crucial to monitor the containers to ensure they are running as expected. This guide provides detailed steps for monitoring and troubleshooting your containers post-deployment.
Deploying the Application¶
To start the application, use the following commands depending on your operating system:
cd apifort
docker compose up -d
dir apifort
docker compose up -d
- The
docker compose up -d
command will start the application in detached mode, allowing it to run in the background.
Monitoring Containers¶
After executing the docker compose up -d
command, it is essential to monitor the status of your containers to ensure they are running smoothly and to detect any potential issues.
Checking Container Status¶
To view the status of all containers, use the following command:
docker compose ps
docker compose ps
- This command will display a list of all containers along with their current status (e.g., "Up", "Exited", etc.).
- Look for any containers that are not in the "Up" state, as this may indicate an issue with the deployment.
Viewing Logs¶
If a container is not running as expected or has exited, you can inspect its logs to identify the root cause of the problem. Use the following command to view logs:
docker compose logs <service-name>
docker compose logs <service-name>
- Replace
<service-name>
with the name of the problematic service. - Review the logs for error messages or warnings that might indicate the source of the issue.
Real-Time Log Monitoring¶
To monitor logs in real-time for all containers, use the following command:
docker compose logs -f
docker compose logs -f
- The
-f
flag allows you to follow the logs as they are being generated.
Troubleshooting Common Issues¶
- Container Exited Immediately:
- Use
docker compose logs <container_name>
to check for errors in the logs. -
Verify that all required environment variables are correctly configured in the
docker-compose.yml
file. -
Port Conflicts:
-
If a container fails to start due to a port conflict, ensure that the ports specified in the
docker-compose.yml
file are not already in use by another service. -
Database Connection Issues:
-
If the application cannot connect to the database, ensure that:
- The database container is running and accessible.
- The credentials in the
docker-compose.yml
file are correct. - The network configuration allows communication between containers.
-
Resource Limitations:
-
If containers are restarting frequently, check the system resources (CPU, memory, disk space) using the
docker stats
command. -
Incorrect Configuration:
- Ensure that all parameters in the
docker-compose.yml
file are correctly configured, especially for services like MinIO, PostgreSQL, and the application.
Stopping and Restarting Containers¶
If you need to stop and restart the containers, use the following commands:
docker compose down
docker compose down
docker compose up -d
docker compose up -d
Additional Commands for Container Management¶
-
View Resource Usage:
BashUse this command to monitor the resource usage (CPU, memory, network) of all running containers in real-time.docker stats
-
Inspect Container Details:
BashUse this command to view detailed information about a specific container.docker inspect <container_name>
Best Practices for Monitoring¶
- Regularly check the status of your containers using
docker compose ps
. - Monitor logs in real-time during critical operations using
docker compose logs -f
. - Ensure that your system has sufficient resources to run all containers smoothly.
- Address any issues promptly to avoid disruptions to the application.