Docker -Compose -Fehler beim Erstellen von Django Dockerfile: Fehler -2 Anschluss an Redis: 6379. Name oder Dienst nichtPython

Python-Programme
Anonymous
 Docker -Compose -Fehler beim Erstellen von Django Dockerfile: Fehler -2 Anschluss an Redis: 6379. Name oder Dienst nicht

Post by Anonymous »

Ich versuche, eine Open-Source-Status-Seitenanwendung mit dem Repository von Status-Page/Status-Page mit Docker Compose einzurichten. Wenn ich Docker -compose -D -D -D -D -Dockerfile beim Build -Prozess des Django -Dienstes auf einen Fehler mache. Der Fehler scheint bei der Aktualisierung und initialisieren Sie die Anwendung, aber ich bin mir nicht sicher, wie ich sie weiter debuggen oder auflösen soll.# Use the official Python runtime image
FROM python:3.12.3

# Create the app directory
RUN mkdir -p /opt/status-page/

# Set the working directory inside the container
WORKDIR /opt/status-page/

# Set environment variables
# Prevents Python from writing pyc files to disk
ENV PYTHONDONTWRITEBYTECODE=1
# Prevents Python from buffering stdout and stderr
ENV PYTHONUNBUFFERED=1

# Install system dependencies
RUN apt-get update && apt install -y libpq-dev gcc

# Create a system user and group
RUN adduser --system --group status-page

# Set ownership of the app directory
RUN chown -R status-page:status-page /opt/status-page/

# Upgrade pip
RUN pip install --upgrade pip

# Copy the Django project to the container
ADD status-page /opt/status-page/

# Grant execute permissions to upgrade.sh
RUN chmod +x /opt/status-page/upgrade.sh

# Install Python dependencies
RUN python -m venv /opt/status-page/venv \
&& /opt/status-page/venv/bin/pip install --no-cache-dir -r requirements.txt

# Upgrade and initialize application
RUN /opt/status-page/upgrade.sh
RUN /opt/status-page/venv/bin/python /opt/status-page/statuspage/manage.py migrate
RUN /opt/status-page/venv/bin/python /opt/status-page/statuspage/manage.py createsuperuser --noinput

# Copy Gunicorn and systemd service files
RUN cp /opt/status-page/contrib/gunicorn.py /opt/status-page/gunicorn.py \
&& cp -v /opt/status-page/contrib/*.service /etc/systemd/system/ \
&& systemctl daemon-reload

# Expose the Django port
EXPOSE 8000

# Start Gunicorn
CMD ["/opt/status-page/venv/bin/gunicorn", "-c", "/opt/status-page/gunicorn.py", "statuspage.wsgi:application"]
< /code>
docker-compose.yml:
version: '3.9'

services:
# PostgreSQL service
db:
image: postgres:15
container_name: status-page-db
environment:
POSTGRES_USER: status-page
POSTGRES_PASSWORD: abcdefgh123456
POSTGRES_DB: status-page
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U status-page -d status-page"]
interval: 10s
timeout: 5s
retries: 5
networks:
- status_page_network

# Redis service
redis:
image: redis:6
container_name: status-page-redis
ports:
- "6379:6379"
hostname: redis_host
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
networks:
- status_page_network

# Django (Status-Page) service
django:
build: ./statuspage
container_name: status-page-django
environment:
DATABASE_NAME: status-page
DATABASE_USER: status-page
DATABASE_PASSWORD: abcdefgh123456
DATABASE_HOST: db
REDIS_HOST: redis_host
REDIS_PORT: 6379
SECRET_KEY: Pv)hkWbYxkpaD_dh$ULGa6MF#ADn6&=MU&#v5cjRyViuTbPHuG
volumes:
- ./status-page:/opt/status-page
- status-page-venv:/opt/status-page/venv
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
expose:
- "8000"
command: /opt/status-page/venv/bin/gunicorn -c /opt/status-page/gunicorn.py statuspage.wsgi:application
networks:
- status_page_network

# Nginx service
nginx:
image: nginx:latest
container_name: status-page-nginx
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./status-page/static:/usr/share/nginx/html/static
ports:
- "80:80"
- "443:443"
depends_on:
- django
networks:
- status_page_network
environment:
- NGINX_HOST=status-page.example.com
- NGINX_PORT=80

volumes:
postgres_data:
status-page-venv:

networks:
status_page_network:
driver: bridge
< /code>
Konfiguration (Snippet): < /p>
ALLOWED_HOSTS = ['*']

# PostgreSQL database configuration. See the Django documentation for a complete list of available parameters:
# https://docs.djangoproject.com/en/stabl ... #databases
DATABASE = {
'NAME': 'status-page', # Database name
'USER': 'status-page', # PostgreSQL username
'PASSWORD': 'abcdefgh123456', # PostgreSQL password
'HOST': 'db', # Database server
'PORT': '5432', # Database port (leave blank for default)
'CONN_MAX_AGE': 300, # Max database connection age
}

# Redis database settings. Redis is used for caching and for queuing background tasks. A separate configuration exists
# for each. Full connection details are required.
REDIS = {
'tasks': {
'HOST': 'redis_host',
'PORT': 6379,
# Comment out `HOST` and `PORT` lines and uncomment the following if using Redis Sentinel
# 'SENTINELS': [('mysentinel.redis.example.com', 6379)],
# 'SENTINEL_SERVICE': 'status-page',
'PASSWORD': '',
'DATABASE': 0,
'SSL': False,
# Set this to True to skip TLS certificate verification
# This can expose the connection to attacks, be careful
# 'INSECURE_SKIP_TLS_VERIFY': False,
},
'caching': {
'HOST': 'redis_host',
'PORT': 6379,
# Comment out `HOST` and `PORT` lines and uncomment the following if using Redis Sentinel
# 'SENTINELS': [('mysentinel.redis.example.com', 6379)],
# 'SENTINEL_SERVICE': 'netbox',
'PASSWORD': '',
'DATABASE': 1,
'SSL': False,
# Set this to True to skip TLS certificate verification
# This can expose the connection to attacks, be careful
# 'INSECURE_SKIP_TLS_VERIFY': False,
}
}
< /code>
Das Problem:
Redis.Exceptions.ConnectionError: Fehler -2 eine Verbindung zu Redis: 6379. Name oder Dienst nicht bekannt. Während des Builds.>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post