Docker does not let me run the Django development server inside the Django container

Hey guys so I’m currently working with a group to create a web application where we are using this repository as our foundation for our project:

The problem I’m encountering is that when I follow the four steps under the “How to use” section, I can’t seem to be able to execute step 4 properly where I get this error:

  • Console command:
    docker run -it --rm -p 8000:8000 -v sqlite:/sqlite -v $(pwd)/website:/usr/src/website insightwrite:master python manage.py runserver 0.0.0.0:8000

  • Result:
    docker: invalid reference format.
    See ‘docker run --help’.

An alternative command I do is this as well:

  • Console command:
    docker run -it --rm -p 8000:8000 -v sqlite:/sqlite -v ${pwd}/website:/usr/src/website insightwrite:master python manage.py runserver 0.0.0.0:8000

  • Result:
    docker: Error response from daemon: Mounts denied:
    The path /website is not shared from the host and is not known to Docker.
    You can configure shared paths from Docker → Preferences… → Resources → File Sharing.
    See Sign in | Docker Docs for more info.
    ERRO[0000] error waiting for container: context canceled

Note that, the only steps I am executing for both situations are steps 2 & 4 because I have already cloned the project and created a superuser before. But I’m unsure if I should create a new superuser every time I open up the console in the project folder’s directory.

Furthermore, the reason why I have “insightwrite:master” in the console command instead of “django-docker-template:master” is because my project name on GitHub is called insightwrite.

If someone could help me with this issue that would be appreciated (:

$(pwd) is a Linux placeholder for current working directory. Maybe just put the absolute path there.

This is what you wrote

docker run -it --rm -p 8000:8000 -v sqlite:/sqlite -v ${pwd}/website:/usr/src/website insightwrite:master python manage.py runserver 0.0.0.0:8000

And this is on GitHub

docker run -it --rm -p 8000:8000 -v sqlite:/sqlite -v $(pwd)/website:/usr/src/website django-docker-template:master python manage.py runserver 0.0.0.0:8000

Notice the difference in ${pwd} which would try to refer to an environment variable and not run a command in a subshell. The same value is in $PWD as well, but that is upper case. With your syntax you get an empty variable as it is probably undefined, but that shouldn’t cause invalid reference format, just mount the wrong directory. So maybe there is something in that variable but not the right one. Fix the parenthesis in your command and that should work.

I almost missed it, because it is harder to notice it in your post. Please, always use code blocks for codes, terminal outputs and logs. More information in the formatting guide: How to format your forum posts

If fixing the parenthesis doesn’t help, you can also quote the path.

docker run -it --rm -p 8000:8000 -v sqlite:/sqlite -v "$(pwd)/website:/usr/src/website" insightwrite:master python manage.py runserver 0.0.0.0:8000

which helps if your working directory has space in its path. I don’t see other problem in the command, but invalid reference format indicates the image name is invalid. That can happen when something before the image name is incorrect and that something else is interpreted as an image name while the actual image name becomes an argument for example. Or the image name becomes a volume and an argument is interpreted as image name.

If you have space in ${pwd}, than the result could be something like this:

docker run -it --rm -p 8000:8000 -v sqlite:/sqlite -v /Users/my user/folder/website:/usr/src/website insightwrite:master python manage.py runserver 0.0.0.0:8000

As you see, /Users/my becomes an anonymous volume’s mount point and user/folder/website:/usr/src/website becomes the image tag, but slashes are not supported in the version tag so you get “invalid reference error”

It worked! Specifically because I didn’t add the quotation marks for the path like you mentioned and sorry for not formatting my code this is my first time on this forum lol. Either way I am pretty thankful for the explanation and I appreciate the help a ton.

The code I used:

docker run -it --rm -p 8000:8000 -v sqlite:/sqlite -v "$(pwd)/website:/usr/src/website" insightwrite:master python manage.py runserver 0.0.0.0:8000