'Dockerfile - Not all commands in CMD are running
When I create an image from the following Dockerfile, the command poetry run python manage.py setstaticpages is skipped (and thus not run). Why is this happening?
NOTE: I've tried to run aforementioned command from inside of shell, and it worked perfectly. However, I need that it is executed when container is built.
# Define Image
FROM python:3.8
# Set Environment Variable
ENV PYTHONUNBUFFERED 1
ENV C_FORCE_ROOT true
# Making source and static directory
RUN mkdir /src
RUN mkdir /static
# Creating Work Directory
WORKDIR /src
# Update pip
RUN pip install --upgrade pip
COPY ./src/poetry.lock /scripts/
COPY ./src/pyproject.toml /scripts/
RUN pip install poetry
CMD ["sh", "-c", "poetry install; poetry run python manage.py collectstatic --no-input; poetry run python manage.py migrate;", "poetry run python manage.py setstaticpages;", "poetry run gunicorn -w 4 -t 180 -b 0.0.0.0:8000 backend.wsgi:application"]
Solution 1:[1]
For chaining commands use either a bash-script and call that in CMD or chain up commands inside shell with &&
CMD [ "sh" , "-c" , "whatever && whatever_next && whatever_last" ]
or
ADD docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
CMD ["/docker-entrypoint.sh"]
#!/bin/bash
#docker-entrypoint.sh
whatever
whatever_next
whatever_last
This may not solve your problem, but this way you'll get proper signal handling by running in one process. So if it still does not work add logs to your question please.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
