0

I'm setting up a django server application on docker. docker runs the container well but the command to run django is not taking by docker.

I've already gone through few youtube videos but none of them worked for me

Dockerfile

FROM python:3.6-stretch

MAINTAINER ***

ENV PYTHONBUFFERED 1

COPY ./requirements.txt /requirements.txt

RUN pip install -r /requirements.txt

RUN mkdir /specfolder
WORKDIR /specfolder
COPY ./myfolder /specfolder

EXPOSE 8000

CMD ["python", "manage.py runserver"]

i've tried placing the command under docker-compose.yml file under

commands: sh -c "python manager.py runserver"

but none of them worked

docker-compose.yml file

version: "3"

services:
myapp:
    build:
        context: .
    ports:
        - "8000:8000"
    volumes:
        - ./myfolder:/specfolder

requriements.txt

django==2.2.4
pandas
xlrd
xlsxwriter

as of now under kinematics i am getting the python shell

Type "help", "copyright", "credits" or "license" for more information.
>>> 2019-08-31T13:34:51.844192800Z Python 3.6.9 (default, Aug 14 2019, 
13:02:21) 
[GCC 6.3.0 20170516] on linux

unable to access the 127.0.0.1:8000/myapp/login in the browser.

1
  • how did you know it didn't work? did you see any error message? Commented Aug 31, 2019 at 14:06

2 Answers 2

1

You need to make changes in your runserver command. Change it to

python manage.py runserver 0.0.0.0:8000

Your Dockerfile will be something like this

# other command
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

Make changes accordingly if you are using Dockerfile or docker-compose.

Sign up to request clarification or add additional context in comments.

Comments

0

I see 2 problems in your implementation.

  1. In Dockerfile you have, CMD ["python", "manage.py runserver"]. It should be CMD ["python", "manage.py", "runserver"]

  2. In compose file commands: sh -c "python manager.py runserver" should be commands: python manager.py runserver.

    1. a. If you use compose file then CMD should be removed from Dockerfile

4 Comments

still no use, when i access localhost:8000 it shows "This site can't be reached" page
now i am able to run the app, but unable to access it browser
Watching for file changes with StatReloader Performing system checks... System check identified no issues (0 silenced). You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. Run 'python manage.py migrate' to apply them. September 03, 2019 - 09:02:55 Django version 2.2.4, using settings 'myproject.settings' Starting development server at 0.0.0.0:8000 Quit the server with CONTROL-C.
i have changed by composer file to this: ` version: '3' services: web: build: . volumes: - .:/myproject ports: - "8000:8000" `

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.