Reputation: 3865
I have following docker file.
MAINTANER Your Name "[email protected]"
RUN apt-get update -y && \
apt-get install -y python-pip python-dev
# We copy just the requirements.txt first to leverage Docker cache
COPY ./requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip install -r requirements.txt
COPY . /app
ENTRYPOINT [ "python" ]
CMD [ "app.py" ]
There is one file that I want to run even before app.py file runs. How can I achieve that? I don't want to put code inside app.py.
Upvotes: 3
Views: 450
Reputation: 1627
One solution could be to use a docker-entrypoint.sh script. Basically that entrypoint would allow you to define a set of commands to run to initialize your program.
For example, I could create the following docker-entrypoint.sh:
#!/bin/bash
set -e
if [ "$1" = 'app' ]; then
sh /run-my-other-file.sh
exec python app.py
fi
exec "$@"
And I would use it as so in my Dockerfile:
FROM alpine
COPY ./docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["app"]
There is a lot of articles and examples online about docker-entrypoints. You should give it a quick search I am sure you will find a lot of interesting examples that are used by famous production grade containers.
Upvotes: 2
Reputation: 10546
You could try creating a bash file called run.sh and put inside
app.py
try changing the CMD
CMD [ "run.sh" ]
Also make sure permission in executable for run.sh
Upvotes: 0