다음 dockerfile 및 docker compose를 사용하여 Django 앱 컨테이너를 빌드하려고 하는데 권한이 거부되었습니다. 일주일 전부터 이 오류를 해결하는 방법을 찾고 있습니다.
Dockerfile-prod
FROM python:3.9-alpine3.13
LABEL maintainer="[email protected]"
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt /tmp/requirements.txt
COPY ./requirements.dev.txt /tmp/requirements.dev.txt
COPY ./scripts /scripts
COPY . /backend
WORKDIR /backend
EXPOSE 8000
ARG DEV=false
RUN python -m venv /py && \
/py/bin/pip install --upgrade pip && \
apk add --update --no-cache postgresql-client jpeg-dev && \
apk add --update --no-cache --virtual .tmp-build-deps \
build-base postgresql-dev musl-dev zlib zlib-dev linux-headers && \
/py/bin/pip install -r /tmp/requirements.txt && \
if [ $DEV = "true" ]; \
then /py/bin/pip install -r /tmp/requirements.dev.txt ; \
fi && \
rm -rf /tmp && \
apk del .tmp-build-deps && \
adduser \
--disabled-password \
--no-create-home \
django-user && \
mkdir -p /vol/web/mediafiles && \
mkdir -p /vol/web/staticfiles && \
chown -R django-user:django-user /vol && \
chmod -R 755 /vol && \
chmod -R +x /scripts
ENV PATH="/scripts:/py/bin:$PATH"
USER django-user
CMD [ "run.sh" ]
그리고 run.sh
#!/bin/sh
set -e
python manage.py wait_for_db
python manage.py makemigrations
python manage.py migrate
python manage.py collectstatic --noinput
gunicorn backend.wsgi --bind 0.0.0.0:8000
도커-작성-prod.yml
version: "3.3"
services:
db:
image: postgres:13-alpine
container_name: db-prod-c
restart: always
volumes:
- db-prod:/var/lib/postgresql/data
environment:
- POSTGRES_DB=${DB_NAME}
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASS}
backend:
build:
context: ./backend
dockerfile: Dockerfile.prod
#restart: always
image: api-prod-i:django-prod
container_name: api-prod-c
volumes:
- mediafiles:/vol/web/mediafiles
- staticfiles:/vol/web/staticfiles
environment:
- DB_HOST=db
- DB_NAME=${DB_NAME}
- DB_USER=${DB_USER}
- DB_PASS=${DB_PASS}
- SECRET_KEY=${DJANGO_SECRET_KEY}
- ALLOWED_HOSTS=${DJANGO_ALLOWED_HOSTS}
expose:
- 8000
depends_on:
- db
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
#restart: always
image: client-prod-i:django-prod
container_name: client-prod-c
volumes:
- react-build:/frontend/build
depends_on:
- backend
proxy:
build:
context: ./webserver
dockerfile: Dockerfile
image: proxy-i
container_name: proxy-c
restart: always
ports:
- 80:80
volumes:
- staticfiles:/webserver/staticfiles
- mediafiles:/webserver/mediafiles
- react-build:/webserver/buildfiles
depends_on:
- backend
- frontend
volumes:
db-prod:
react-build:
staticfiles:
mediafiles:
docker-compose-prod를 실행한 후 다음 오류가 발생합니다.
PermissionError: [Errno 13] Permission denied: '/vol/web/staticfiles/admin'
api-prod-c exited with code 1
Dockerfile에서 권한 777을 사용하여 /vol 폴더를 chmod하려고 시도했지만 여전히 동일한 오류가 발생합니다. 나는 ubuntu 22.04를 사용하고 있으며 docker 명령과 함께 sudo를 사용한다고 언급했습니다. sudo 없이 docker 명령을 사용하면 다음 오류가 발생합니다.
ot permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/images/json": dial unix /var/run/docker.sock: connect: permission denied
첫 번째 오류를 방지하기 위해 Dockerfile을 수정하려면 어떻게 해야 합니까?