In this section there are some interesting tips that can be useful for debugging errors or checking the database.
NOTE: From July 2024 onwards, the instruction for Docker Compose in mac is without hyphen, so from now on,
docker-compose up -disdocker compose up -dwhen executing in macOS.
Ie when developing and doing changes in git repo.
-
Stop all containers and remove all images:
docker-compose down --rmi all
-
Rebuild images avoiding cache:
docker-compose build --no-cache
-
Rebuild a single service avoiding cache but preserving the rest of services (only service_name has changed):
docker-compose build --no-cache <service_name>
-
Up services:
docker-compose up -d
A rebuild script is provided for rebuilding one or more services in an automatic way. Please execute the script, located in scripts/rebuild.py.
How to execute the help script from the root of this repository:
python3 scripts/rebuild.py -hExample for rebuilding the client and vre_lite services from the my_stack stack:
python3 scripts/rebuild.py -s client vre_lite -t my_stackFor performing the same process step by step:
-
Rebuild the Service Image Without Cache: Use docker-compose to rebuild the image locally, targeting only the service you want to update:
docker-compose build --no-cache <service_name>
-
Update the Service in the Swarm: In Docker Swarm, you can force the service to use the updated image by running:
docker service update --force <stack_name>_<service_name>
-
Remove Stopped Container(s): After updating the service, the old container remains stopped, execute the following instruction for removing it:
docker container prune -f
-
Remove Unused Image(s): After rebuilding the image, the old image remains unused, execute the following instruction for removing it:
docker image prune -f
When working with Docker, even after removing images and containers, Docker can leave behind various unused resources that take up disk space. To clean up your system effectively, you can use the following commands:
-
Remove unused containers, images and networks:
Docker has a built-in command to clean up resources that are not in use:
docker system pruneThis command will prompt you to confirm that you want to remove all unused data. If you want to avoid the prompt, you can add the -f (force) flag:
docker system prune -f -
Cleaning up the Docker builder cache:
Docker build cache can also take up significant space. You can remove unused build cache:
docker builder pruneIf you want to remove all build cache, including the cache used by the active build process:
docker builder prune -a -f -
Remove unused volumes:
By default, docker system prune does not remove unused volumes. If you want to remove them as well, you can use:
docker system prune --volumesIf you want to avoid the prompt, you can add the -f (force) flag:
docker system prune --volumes -fTo ensure, list volumes:
docker volume lsFor removing all volumes (beware):
docker volume rm $(docker volume ls -q) -
Remove unused networks:
Usually, the steps above remove the networks related to the project, but this instruction removes the unused networks:
docker network prune -fTo ensure, list networks:
docker network ls -
Check disk usage by Docker objects
docker system df
Add two more replicas to my_stack_website:
docker service scale my_stack_website=4Stop my_stack_mongo-backup service:
docker service rm my_stack_mongo-backupdocker service ps my_stack_mongodbIn case of errors, use the --no-trunc flag for the sake of seeing the whole error text:
docker service ps my_stack_mongodb --no-truncdocker exec -it <mongo_container_ID> bashAnd then:
mongosh For entering the database in terminal mode. Take into account that, for checking your database and its collections, you must use the authentication credentials defined in the mongo-init.js file. For example, for checking the collections of the mddb_db database, please follow the next steps:
Switch to mddb_db database (or the name defined in the mongo-init.js file):
use mddb_db
Authenticate with one of the users defined in the mongo-init.js file:
db.auth('user_r','pwd_r');
Execute some mongo shell instruction:
show collections
Additionally, users are able to access the database as a root/admin user, as defined in the docker-compose.yml file:
mongosh --username <ROOT_USER> --password <ROOT_PASSWORD>
Take into account that acessing mongoDB as root/admin user is not recommended as with this user there are no restrictions once inside the database. We strongly recommend to use the users defined in the mongo-init.js file for accessing the database.
Show logs for a container:
docker logs my_restdocker logs <apache_container_ID>