Answer the question
In order to leave comments, you need to log in
How to use multiple blocking commands in docker-compose?
Good afternoon.
I'm getting closer to docker-compose, but the question arose of how to execute a few commands to run a project on django and connect gunicorn.
The project uses: django, rqworker(redis), rqscheduler(redis), postgres.
On the local machine, I launch the project using 3 terminals (because each of them is blocking):
1. terminal:
<env>[email protected]: python manage.py rqworker
2. terminal:
<env>[email protected]: python manage.py rqscheduler
3. terminal:
<env>[email protected]: python manage.py runserver
Question 1:
What should docker-compose look like to run these 3 commands (if you know how to connect redis and postgres, please help with this too)?
There is a desire to connect gunicorn, but how to do it?
Answer the question
In order to leave comments, you need to log in
We need to write a script that will play the role of ENTRYPOINT. Such a script can have very rich functionality, but it will be enough to solve the problem:
#!/bin/sh
set -e
if [ "x$DJANGO_MANAGEPY_MIGRATE" = 'xenable' ]; then
python manage.py migrate --noinput
fi
if [ "x$DJANGO_MANAGEPY_COLLECTSTATIC" = 'xenable' ]; then
python manage.py collectstatic --noinput
fi
if [ "x$DJANGO_MANAGEPY_LOADDATA" = 'xenable' ]; then
python manage.py loaddata fixtures/initial_data.json
fi
if [ "x$DJANGO_MANAGEPY_PARALLELRUN" = 'xenable' ]; then
python manage.py rqworker &
python manage.py rqscheduler &
python manage.py runserver &
fi
exec "[email protected]"
version: "3.9"
services:
db:
container_name: mysql
image: mysql:8.0.22
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
command: --default-authentication-plugin=mysql_native_password
volumes:
- /data:/var/lib/mysql
restart: always
networks:
- net
django:
container_name: django
build:
context: .
args:
USER_ID: ${USER_ID}
GROUP_ID: ${GROUP_ID}
USER_NAME: ${USER_NAME}
GROUP_NAME: ${GROUP_NAME}
DOMAIN_NAME: ${DOMAIN_NAME}
RUN_DEPS: ${RUN_DEPS}
BUILD_DEPS: ${BUILD_DEPS}
environment:
DJANGO_MANAGEPY_MIGRATE: ${DJANGO_MANAGEPY_MIGRATE}
DJANGO_MANAGEPY_COLLECTSTATIC: ${DJANGO_MANAGEPY_COLLECTSTATIC}
DJANGO_MANAGEPY_COLLECTSTATIC: ${DJANGO_MANAGEPY_COLLECTSTATIC}
DJANGO_MANAGEPY_LOADDATA: ${DJANGO_MANAGEPY_LOADDATA}
DJANGO_MANAGEPY_PARALLELRUN: ${DJANGO_MANAGEPY_PARALLELRUN}
command: gunicorn ${WSGI}.wsgi:application --user ${USER_NAME} --group ${GROUP_NAME} --name ${APP_NAME} --workers ${WORKERS} --max-requests ${MAX_REQ} --timeout ${TIMEOUT} --preload --bind=unix:/var/www/${USER_NAME}/data/tmp/${APP_NAME}.sock
volumes:
- /blabla:/blabla
depends_on:
- db
restart: always
networks:
- net
networks:
net:
name: net
docker-compose doesn't know commands
, it's a docker container launcher.
your task is to learn how to pack your applications into a container (in this case, three different containers), and then write a script for launching these three containers + postgres + radish and what else is needed ..
here is an excellent manual on the docker off site how to wrap a python application to container
https://docs.docker.com/language/python/build-images/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question