Launching Tech Stack in order to Python, Flask Framework and MongoDB with Docker Compose. For this documentation, I have an interesting full article that I recommend you Python, Flask, MongoDB with Docker Compose.
First, making clone to this project, doing:
git clone https://github.com/jersonmartinez/Python-Flask-MongoDB-with-Docker-Compose.git
And then, execute the Docker Compose instruction to launch Tech Stack (Python
, Flask
and MongoDB
).
docker-compose up -d
Update the file .env
(environment variables) with your specify credentials.
WEB_HOST=cs_api
MONGO_HOST=cs_mongodb
MONGO_PORT=27017
MONGO_USER=root-crashell
MONGO_PASS=password-crashell
MONGO_DB=db_crashell
Other important file is mongo-init.js
.
db.createUser(
{
user: 'root-crashell',
pwd: 'password-crashell',
roles: [
{ role: "clusterMonitor", db: "admin" },
{ role: "dbOwner", db: "db_name" },
{ role: 'readWrite', db: 'db_crashell' }
]
}
)
This result is using the curl
tool.
$ curl 127.0.0.1:8000
<h1 style="background-color: #262626; color: white; padding: 20px; text-align:center;">Hello, Crashell!</h1>
Result using the browser.
Execute the following instruction using curl
or the browser.
$ curl 127.0.0.1:8000/api
"Connected to the MongoDB Server!"
Result using the browser.
We have two ways to remove our volumes with Docker.
First is using prune
command.
docker volume prune -f
Second is using the current command volume rm
with -f
like parameter.
docker volume rm $(docker volume ls -q)
rm -rf mongo-volume app/__pycache__/ && mkdir mongo-volume
docker system prune -a -f && docker builder prune -a -f
docker-compose up --build --force-recreate --no-deps -d web
docker logs --tail 1000 -f cs_api