我用 Docker Compose 创建了 Django 项目:
Dockerfile
FROM python:2.7
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD . /code/
RUN pip install -r requirements.txt
WORKDIR /code/example
ENTRYPOINT ["python", "manage.py"]
码头工人-compose.yml
postgres:
image: postgres
ports:
- '5432:5432'
django-project:
build: .
command: runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- '8000:8000'
links:
- postgres
它工作得很好。但是通过容器“django-project”创建的所有新文件都有根所有者和组。
我尝试user: user
为容器添加 Compose 配置django-project
。但有异常User user not found
。
我尝试user
使用代码添加容器:
ENV HOME_USER user
ENV HOME_PASS password
RUN useradd -m -s /bin/bash ${HOME_USER} && \
echo "${HOME_USER}:${HOME_PASS}"|chpasswd && \
adduser ${HOME_USER} sudo && \
echo ${HOME_USER}' ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
但异常仍然存在。
如何为将通过 docker 容器创建的所有新文件应用非 root 所有权?