geoguncay / django_microservice

Simple aplications where exceute django famework with djangorestframework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Django application in dev mode in Docker with djangorestframework

Project structure:

.
├── compose.yaml
├── core
├── api
├── Dockerfile
├── requirements.txt
└── manage.py

compose.yaml

services:
  web:
    build: .
    container_name: django
    volumes:
      - .:/microservice
    ports:
      - "8000:8000"

Dockerfile

FROM --platform=$BUILDPLATFORM python:3.8 AS builder

EXPOSE 8000

WORKDIR /microservice

COPY requirements.txt /microservice

RUN python -m pip install --upgrade pip

RUN python -m pip install --upgrade django

RUN python -m pip install -r requirements.txt

COPY . /microservice

ENTRYPOINT ["python3"]

CMD ["manage.py", "runserver", "0.0.0.0:8000"]

Deploy with docker compose

$ docker compose up -d

Expected result

Listing containers must show one container running and the port mapping as below:

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                    NAMES
b99abb5e954a        microservice-web    "python3 manage.py r…"   About a minute ago   Up About a minute   0.0.0.0:8000->8000/tcp   django```

After the application starts, navigate to `http://localhost:8000` in your web browser:

Stop and remove the containers

```cmd
$ docker compose down```

Too see API navigate to http://localhost:8000/api/v1/ in your web browser.

Too see Documentation navigate to http://localhost:8000/docs/ in your web browser.

About

Simple aplications where exceute django famework with djangorestframework


Languages

Language:Python 94.4%Language:Dockerfile 5.6%