From 1b0f5c93bee0a119ef3ab9d4ee7a34bd6230fbb7 Mon Sep 17 00:00:00 2001 From: Raghad Dahi Date: Thu, 7 May 2026 15:10:20 +0300 Subject: [PATCH] Add Docker Compose setup --- Makefile | 14 ++++++++++---- README.md | 13 ++++++++----- docker-compose.yml | 25 +++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 docker-compose.yml diff --git a/Makefile b/Makefile index a04fd8f3..a86778a5 100644 --- a/Makefile +++ b/Makefile @@ -54,13 +54,19 @@ compilemessages: cd apps && poetry run python ../manage.py compilemessages docker-build: - docker build -t guide:latest --build-arg POETRY_INSTALL_ARGS="" -f Dockerfile . + docker compose build docker-run: - docker run --name guide_latest -p ${PORT}:${PORT} --env-file .env guide:latest sh -c 'poetry run python manage.py runserver 0.0.0.0:${PORT}' + docker compose up --remove-orphans + +docker-start: + docker compose up --remove-orphans -d + +docker-stop: + docker compose down docker-exec: - docker exec -it guide_latest /bin/bash + docker compose exec web /bin/bash docker-init: - docker exec -it guide_latest /bin/bash -c "make backend" + docker compose exec web make backend diff --git a/README.md b/README.md index d2333e50..208246fa 100644 --- a/README.md +++ b/README.md @@ -71,17 +71,20 @@ Or both, in a single command: ### Setting up development with Docker -1. Create a `.env` file in the project root containing these variables, you can adjust the values to your preferences: +1. Optianally, create a `.env` file in the project root containing these variables, you can adjust the values to your preferences: ``` ALLOWED_HOSTS=localhost PORT=8000 SECRET_KEY=some-random-secret DJANGO_SETTINGS_MODULE=apps.guide.settings.dev ``` -2. Build the image by running the `make docker-build` command. -3. Run the container with `make docker-run`. -4. Run the init script in the container: `make docker-init` -5. You should now have access to the project in your browser at `http://localhost:8000` +2. Build and start the development container by running the `make docker-run` command. + This starts the server in the foreground. To run it in the background, use `make docker-start` instead. +3. In another terminal, run the init script in the container: `make docker-init` +4. You should now have access to the project in your browser at `http://localhost:8000` +5. To stop the container, run `make docker-stop` + +Code changes are picked up automatically. Only rebuild when dependencies change:`make docker-build` # Gitpod diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..f1afab4b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +services: + web: + build: + context: . + args: + POETRY_INSTALL_ARGS: '' + ports: + - '${PORT:-8000}:${PORT:-8000}' + environment: + DJANGO_SETTINGS_MODULE: apps.guide.settings.dev + env_file: + - path: .env + required: false + volumes: + - .:/app + - staticfiles:/app/static + command: + - poetry + - run + - python + - manage.py + - runserver + - '0.0.0.0:${PORT:-8000}' +volumes: + staticfiles: