I am new to Docker. I am trying to run a basic project that I have made in Django. My Dockerfile is:
FROM python:3
COPY members /associate/
WORKDIR /associate
RUN pip install Django
WORKDIR /associate/forening
EXPOSE 8000
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
My django project is in a folder called members. I use docker build -t testdocker:1.0 .
to build the image. The output from running this is:
`[+] Building 4.9s (10/10) FINISHED docker:desktop-linux`
`=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 553B 0.0s
=> [internal] load .dockerignore 0.1s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/python:3 1.9s
=> [internal] load build context 2.7s
=> => transferring context: 854.31kB 2.6s
=> [1/5] FROM docker.io/library/python:3@sha256:3733015cdd1bd7d9a0b9fe21 0.0s
=> CACHED [2/5] COPY members /associate/ 0.0s
=> CACHED [3/5] WORKDIR /associate 0.0s
=> CACHED [4/5] RUN pip install Django 0.0s
=> CACHED [5/5] WORKDIR /associate/forening 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:59657eb3bc6283ed9ec202cc9672604815a95e6062a9c 0.0s
=> => naming to docker.io/library/testdocker:1.0 0.0s`
and then i run it in docker desktop.
What I am trying to do in Dockerfile is to install django to the virtual environment of the django project which has been copied to the folder associate. But I can’t find the server http://0.0.0.0:8000/ which exists on my computer locally when i run the django project.
On a slightly unrelated question, where are my docker images and containers stored? When I run docker info it says that docker root directory is var/lib/docker but no such directory exists. Right now I am running docker images from the graphical user interface in docker desktop
0.0.0.0
is an IP address that, in the context of servers and containers, means "every IPv4 of the server/container".
The idea is that containers are stateless, so you (and your Django application) never know what IP address Docker will assign to the container. Therefore 0.0.0.0
allows your Django application to listen on the IP address of your container without knowing it before initialization.
If you want to reach your Django application from your host machine, you need to expose ports of the container using port exposition which will allow you to reach your container using localhost:<src-port>
.
As of where Docker store images, it actually stores "layers" which are what images are made of. I'll let you read this documentation for more informations. But image storage is rarely something you interact with.