-1

I have django project and I want to dockerize it. when I use python manage.py runserver 0.0.0.0:8000 on my system its work: view result picture, but when I try use this command on docker, django server is not running view result picture

This is my Dockerfile that used for build docker image:

FROM python:3.9
ENV PYTHONUNBUFFERED=1
RUN mkdir /app
WORKDIR /app
COPY requirements.txt /app/
RUN pip install -r requirements.txt
COPY . /app/

I can dockerize project without mysql database(with sqlite) successfully(for test), but i need to connect to this database.

this is my database setting config(in settings.py file):

can anyone help me to find solution?

Yousef
  • 3
  • 5
  • Follow [this](https://docs.docker.com/samples/django/) guide. – Sunderam Dubey Aug 14 '22 at 06:40
  • I tried this before, and faced with this problem again – Yousef Aug 14 '22 at 06:49
  • Where is your `docker-compose` code inside it add `command: "python manage.py runserver 0.0.0.0:8000"` and then build your image run `docker-compose up` it will run your django server – Ankit Tiwari Aug 14 '22 at 07:33
  • I know that you what say and before test it, but when run docker-compose up i take same result – Yousef Aug 14 '22 at 08:31
  • What's the output of the container when it starts up; is it the literal string `view result picture`, or is there some text-format output you can include directly in the question? How are you starting the container? Why do you think it doesn't work? – David Maze Aug 14 '22 at 10:41
  • I start container with "docker run ", i think maybe this problem caused by exists some package(like as mysql or python development packeages) in my ubuntu and dosen't exist in docker container, or maybe not / i don't understand first part of your questions please explain it. – Yousef Aug 14 '22 at 13:36
  • I guess you also need to setup a docker-compose file for binding MySQL – csgeek Aug 14 '22 at 18:19

1 Answers1

2

The Dockerfile is not complete. It misses a line like:

CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
Ali
  • 922
  • 1
  • 9
  • 24
Andrea
  • 46
  • 1
  • 3
  • thanks but This line only shorter "docker run" command, and don't solve my problem – Yousef Aug 14 '22 at 07:41
  • **Any Docker image must have an ENTRYPOINT or CMD declaration for a container to start.** Though the ENTRYPOINT and CMD instructions may seem similar at first glance, there are fundamental differences in how they build container images. see [this question](https://stackoverflow.com/questions/59599659/is-cmd-or-entrypoint-necessary-to-mention-in-dockerfile) – Ali Aug 14 '22 at 08:36