得到错误:创建装载源路径“ / var / www / trialriskincident-backend / db-init”时无法启动服务数据库:错误:

时间:2019-12-16 08:36:44

标签: python django docker docker-compose dockerfile

我在docker中是新来的,我的项目在django python中,当我运行sudo docker-compose up命令时,终端出现错误,有人可以帮忙吗我要解决这个问题吗?

Starting trialriskincident-backend_db_1 ... 
Starting trialriskincident-backend_app_1 ... error

Starting trialriskincident-backend_db_1  ... error
ir /var/www: read-only file system

ERROR: for trialriskincident-backend_db_1  Cannot start service db: error while creating mount source path '/var/www/trialriskincident-backend/db-init': mkdir /var/www: read-only file system

ERROR: for app  Cannot start service app: error while creating mount source path '/var/www/trialriskincident-backend': mkdir /var/www: read-only file system

ERROR: for db  Cannot start service db: error while creating mount source path '/var/www/trialriskincident-backend/db-init': mkdir /var/www: read-only file system
ERROR: Encountered errors while bringing up the project.

Dockerfile

FROM python:3.7
ENV PYTHONUNBUFFERED 1

RUN apt-get update && apt-get install -y --no-install-recommends \
        python-dev \
        default-libmysqlclient-dev \
        && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

COPY requirements.txt /requirements.txt
RUN pip install -r /requirements.txt

RUN mkdir /app
COPY ./ /app

docker-compose.yml

version: "3"
services:

  app:
    build:
      context: .
    ports:
      - "8000:8000"
    volumes:
      - ./:/app
    command: >
      sh -c "python app/manage.py runserver 0.0.0.0:8000"

# Services
  db:
    image: mysql:5.7
    #restart: no
    environment:
      # Password for root access
       MYSQL_ROOT_PASSWORD: '12345678'
       MYSQL_DATABASE: 'trail_risk_inc_backend'
    ports:
      # <Port exposed> : < MySQL Port running inside container>
      - '3306'
    expose:
      # Opens port 3306 on the container
      - '3306'
      # Where our data will be persisted
    volumes:
      - ./db-init:/docker-entrypoint-initdb.d

1 个答案:

答案 0 :(得分:0)

您正在安装的卷中没有容器用户的写权限

请注意,您的sudo适用于docker-compose命令,但不适用于容器的内容。

这是一个疯狂的猜测,但是可能您正在将/var/www作为卷安装到容器上,并且该容器不是以root的身份运行,而是以其他用户身份运行,因此该用户没有无法访问/var/www