Docker enables developers to pack applications into containers that run as instances of a docker image and contain their own operating system as well as all the necessary dependencies. This makes it easier, simpler and safer to build, deploy and manage your apps.
docker compose enables running & management of a multi-container application in a simple way using the YAML file (docker-compose.yml) defining all the required services.
For out example we will use 2 services:
basic project setup
In the dockerfile we will use the requirements.txt file to install all the necessary packages.
Before, make sure you have the following packages installed:
Next create the requirements.txt file:
Dockerfile for our python/django app:
The docker-compose file including two services:
web(django web app) and db (postgres db)
Commands to execute
Now run the containers:
docker-compose up -d
Stop the containers:
View the logs of a container:
docker-compose logs <service_name>
List the running containers:
Get inside the web container to execute other commands (i.e. createsuperuser)
docker exec -it <container_id> /bin/sh