Хочу собрать django приложение с помощью докера, docker yml выглядит следующим образом:
version: '3'
services:
postgres:
image: postgres:alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
- POSTGRES_USER=***
- POSTGRES_PASSWORD=***
- POSTGRES_DB=***
ports:
- 5433:5432
redis:
image: redis:5
magras-box:
build: .
command: sh -c "python manage.py makemigrations && python manage.py migrate && python manage.py runserver"
volumes:
- media_data:/usr/src/TextGame/media
- chat_data:/usr/src/TextGame/chat/chats_data
- action_data:/usr/src/TextGame/chat/actions_data
ports:
- 127.0.0.1:8000:8000
environment:
- SECRET_KEY=***
- db_password=***
- db_host=postgres
- channel_host=redis
volumes:
media_data:
chat_data:
action_data:
postgres_data:
Dockerfile:
FROM python:3.10-alpine
WORKDIR /web-app
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
COPY . .
RUN pip install -r requirements.txt
Результат docker-compose up:
(.venv) PS C:\Users\Magras\projectsPY\TextGame> docker-compose up
[+] Running 17/2
✔ redis 6 layers [⣿⣿⣿⣿⣿⣿] 0B/0B Pulled 27.9s
✔ postgres 9 layers [⣿⣿⣿⣿⣿⣿⣿⣿⣿] 0B/0B Pulled 31.7s
[+] Building 88.9s (9/9) FINISHED docker:default
=> [magras-box internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 192B 0.0s
=> [magras-box internal] load .dockerignore 0.1s
=> => transferring context: 137B 0.0s
=> [magras-box internal] load metadata for docker.io/library/python:3.10-alpine 2.0s
=> [magras-box 1/4] FROM docker.io/library/python:3.10-alpine@sha256:8a66e74c0581e0c7b8b481fe7f0444b2fd599685d4fb525c1047da4f6f44fdaa 0.0s
=> [magras-box internal] load build context 3.9s
=> => transferring context: 1.45MB 3.7s
=> CACHED [magras-box 2/4] WORKDIR /web-app 0.0s
=> [magras-box 3/4] COPY . . 7.4s
=> [magras-box 4/4] RUN pip install -r requirements.txt 69.9s
=> [magras-box] exporting to image 5.3s
=> => exporting layers 5.3s
=> => writing image sha256:5207fc5b0f855c4ec556ab4cf5ddf8f176f34a6e948ccafa22d4e2dea92c4d6f 0.0s
=> => naming to docker.io/library/textgame-magras-box 0.0s
[+] Running 4/4
✔ Network textgame_default Created 0.2s
✔ Container textgame-magras-box-1 Created 0.6s
✔ Container textgame-postgres-1 Created 0.6s
✔ Container textgame-redis-1 Created 0.6s
Attaching to magras-box-1, postgres-1, redis-1
postgres-1 |
postgres-1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
redis-1 | 1:C 01 Jan 2024 18:27:41.996 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
postgres-1 |
redis-1 | 1:C 01 Jan 2024 18:27:41.997 # Redis version=5.0.14, bits=64, commit=00000000, modified=0, pid=1, just started
redis-1 | 1:C 01 Jan 2024 18:27:41.997 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis-1 | 1:M 01 Jan 2024 18:27:42.011 * Running mode=standalone, port=6379.
redis-1 | 1:M 01 Jan 2024 18:27:42.012 # Server initialized
redis-1 | 1:M 01 Jan 2024 18:27:42.012 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memo
ry = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis-1 | 1:M 01 Jan 2024 18:27:42.012 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with R
edis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a
reboot. Redis must be restarted after THP is disabled.
redis-1 | 1:M 01 Jan 2024 18:27:42.013 * Ready to accept connections
postgres-1 | 2024-01-01 18:27:42.131 UTC [1] LOG: starting PostgreSQL 16.1 on x86_64-pc-linux-musl, compiled by gcc (Alpine 13.2.1_git20231014) 13.2.1 20231014, 64-bit
postgres-1 | 2024-01-01 18:27:42.131 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres-1 | 2024-01-01 18:27:42.132 UTC [1] LOG: listening on IPv6 address "::", port 5432
postgres-1 | 2024-01-01 18:27:42.159 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres-1 | 2024-01-01 18:27:42.212 UTC [24] LOG: database system was shut down at 2024-01-01 18:25:06 UTC
postgres-1 | 2024-01-01 18:27:42.254 UTC [1] LOG: database system is ready to accept connections
magras-box-1 | No changes detected
magras-box-1 | Operations to perform:
magras-box-1 | Apply all migrations: admin, auth, authsys, authtoken, captcha, contenttypes, mainapp, sessions
magras-box-1 | Running migrations:
magras-box-1 | No migrations to apply.
magras-box-1 | Watching for file changes with StatReloader
magras-box-1 | Performing system checks...
magras-box-1 |
magras-box-1 | System check identified no issues (0 silenced).
magras-box-1 | January 01, 2024 - 20:28:12
magras-box-1 | Django version 4.2.5, using settings 'MagrasBox.settings'
magras-box-1 | Starting ASGI/Daphne version 4.0.0 development server at http://127.0.0.1:8000/
magras-box-1 | Quit the server with CONTROL-C.
Но в итоге почему-то не пробрасывается порт и запрос на localhost:8000 просто не производится. Однако, если сделать запрос внутри одного из контейнеров сети докера, все работает. Что интересно, подключение к базе данных с хоста работает, при подключении к 127.0.0.1:5433 я могу пользоваться базой данных.
Использую docker desktop в качестве замены docker engine, так как сижу на винде. Как решить проблему?