Reputation: 1241
I want to create a python Django container. I have a Dockerfile
as shown below -
FROM python:3.7-slim
ENV PYTHONUNBUFFERED 1
RUN apt-get update
RUN apt-get install python3-dev default-libmysqlclient-dev gcc -y
COPY ./requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
RUN mkdir /eitan_app
WORKDIR /eitan_app
COPY . /eitan_app
EXPOSE 8000
RUN python3 manage.py makemigrations
RUN python3 manage.py migrate
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
I created image with the command mentioned below -
docker build -t gcr.io/eitan-269907/eitan-app:v1 .
The above command created image successfully. Now I want to create a running container of the image so run command -
docker run --rm -p 8000:8000 gcr.io/eitan-269907/eitan-app:v1
The above command exited without any error code. So I run command docker ps -a
to check the status of container.
The container was not running. Hence I tried to check the logs with command docker logs -f <container id>
but command did not return any thing.
I don't understand what is wrong with my configuration. I have been trying to look for the solution and found nothing.
Upvotes: 1
Views: 627
Reputation: 909
This could be due to some error in running makemigration
or some other script,
In such case I try to use Entrypoint as '/dev/null' so that container doesn't exit,
This gives chance to log into container and execute them manually to check what's core issue
For your case would suggest
FROM python:3.7-slim
ENV PYTHONUNBUFFERED 1
RUN apt-get update
RUN apt-get install python3-dev default-libmysqlclient-dev gcc -y
COPY ./requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
RUN mkdir /eitan_app
WORKDIR /eitan_app
COPY . /eitan_app
ENTRYPOINT ["tail", "-f", "/dev/null"]
Once you build this image and execute same, it will keep container running
you can then use docker exec -it <container_name> bash
which will allow you to log into container and execute rest of commands and see if it's giving some error
Upvotes: 2
Reputation: 53
When you run it with the --rm
flag, it removes the container after the command or job it is supposed to do is complete. This explains why you are not seeing anything when trying to view the logs or with ps -a
. Try to run the container with -d
(detach) instead of --rm
and see if the container stays running after.
Upvotes: 1