Reputation: 6822
I'm trying to run a Docker container which complains with the error message: /bin/sh: gunicorn: not found
. Firing up the server locally without Docker works fine. And building the image also works fine. I'm new to docker so I don't know if anything looks weird in my Dockerfile..
My Dockerfile:
FROM python:3.7-alpine
RUN adduser -D teamreacher
WORKDIR /home/teamreacher
# copy and install dependencies
COPY ./requirements.txt requirements.txt
RUN python -m venv venv
RUN venv/bin/pip install --upgrade pip
RUN venv/bin/pip install -r requirements.txt
# copy the app
COPY . .
RUN chmod +x boot.sh
RUN chown -R teamreacher:teamreacher ./
USER teamreacher
# expose port and run server
EXPOSE 5000
RUN source venv/bin/activate
CMD gunicorn -b :5000 --access-logfile - --error-logfile - wsgi:app
And my requirements.txt:
Flask==1.0.2
Flask-RESTful==0.3.6
Flask-SQLAlchemy==2.3.2
Flask-JWT==0.3.2
Flask-Cors==3.0.7
gunicorn==19.9.0
Upvotes: 9
Views: 17797
Reputation: 175
My packages installation looked like this:
RUN pip install -r requirements.txt --target=/app/python
I had to remove the --target=/app/python
then pod status started showing Running
(got fixed).
So the fix for me was:
RUN pip install -r requirements.txt
Upvotes: -1
Reputation: 12139
A RUN
command creates a layer, it's like running the command in a new shell. When it completes, the 'shell' exits. So any following commands will not be affected.
You can add a shell script (startup.sh) like,
#!/bin/sh
source venv/bin/activate
gunicorn -b :5000 --access-logfile - --error-logfile - wsgi:app
then CMD ["./startup.sh"]
PS:
There is little interest for using virtual env in docker container. A container is already an isolated environment and it's supposed to do only one thing.
Upvotes: 11