I am trying to create container with following docker file. Since it is going to execute last CMD, it ignores CMD ["sh", "-c", "python3 run_scheduler.py --config=${config}"]
. Is there a way to run both from single docker file. Also, is it possible to pass ${config}
argument to flask api in CMD ["gunicorn", "--bind", "0.0.0.0:5000", "run_api:application", "&"]
FROM python:3.8
LABEL version="0.1"
WORKDIR /app
COPY . /app
ARG config=dev
RUN pip install -r requirements.txt
EXPOSE 5000
CMD ["sh", "-c", "python3 run_scheduler.py --config=${config}"]
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "run_api:application", "&"]
As mentioned in comments you can pass 2-line bash script in CMD. This can cause problems however. Docker is not really meant to run multiple processes in single container. I already see "&" argument in your second CMD. I guess you had problems with second process wasn't running so you tried to push it to the background.
The solution recommended by Docker is to run supervisord
inside the container: https://docs.docker.com/config/containers/multi-service_container/
From naming concepts I guess you can solve your problem with Flask-APScheduler https://github.com/viniciuschiele/flask-apscheduler This way you can get rid of second sidecar script.
And lastly you asked:
Also, is it possible to pass ${config} argument to flask api
and answer is yes. Declare ENV
in your Dockerfile like so:
FROM python:3.8
...
...
ENV config foo
...
CMD ["whatever_command", "--option", "${config}"]
This way "${config}"
will be replaced with value foo
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.