gpt4 book ai didi

django - 在我的Docker镜像中挂载了本地目录,但无法从该目录读取文件

转载 作者:行者123 更新时间:2023-12-02 19:00:36 27 4
gpt4 key购买 nike

我正在尝试使用MySql,Django和Apache镜像构建docker容器。我已经设置了这个docker-compose.yml ...

version: '3'

services:
mysql:
restart: always
image: mysql:5.7
environment:
MYSQL_DATABASE: 'maps_data'
# So you don't have to use root, but you can if you like
MYSQL_USER: 'chicommons'
# You can use whatever password you like
MYSQL_PASSWORD: 'password'
# Password for root access
MYSQL_ROOT_PASSWORD: 'password'
ports:
- "3406:3306"
volumes:
- my-db:/var/lib/mysql
command: ['mysqld', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci']

web:
restart: always
build: ./web
ports: # to access the container from outside
- "8000:8000"
env_file: .env
environment:
DEBUG: 'true'
command: /usr/local/bin/gunicorn maps.wsgi:application --reload -w 2 -b :8000
volumes:
- ./web/:/app
depends_on:
- mysql

apache:
restart: always
build: ./apache/
ports:
- "9090:80"
links:
- web:web

volumes:
my-db:

我想将docker Django镜像挂载到本地计算机上的目录中,以便可以在docker容器中反射(reflect)本地编辑,这就是为什么我要这样做
volumes:
- ./web/:/app

在我的“网络”部分中。这是我正在使用的Web / Dockerfile ...
FROM python:3.7-slim

RUN apt-get update && apt-get install

RUN apt-get install -y libmariadb-dev-compat libmariadb-dev
RUN apt-get update \
&& apt-get install -y --no-install-recommends gcc \
&& rm -rf /var/lib/apt/lists/*

RUN python -m pip install --upgrade pip

WORKDIR /app/

COPY requirements.txt requirements.txt
RUN python -m pip install -r requirements.txt

RUN ["chmod", "+x", "/app/entrypoint.sh"]

ENTRYPOINT ["/app/entrypoint.sh"]

但是,当我使用“docker-compose up”运行程序时,出现此错误...
chmod: cannot access '/app/entrypoint.sh': No such file or directory

即使当我查看本地目录时,也可以看到文件...
localhost:maps davea$ ls -al web/entrypoint.sh 
-rw-r--r-- 1 davea staff 99 Mar 9 15:23 web/entrypoint.sh

我感觉我没有正确地映射/装载东西,但是不确定问题出在哪里。

最佳答案

看来您的docker-composeDockerfiles设置正确。

但是,我注意到的一件事是,您的入口点ENTRYPOINT ["/app/entrypoint.sh"]正在执行文件/app/entrypoint.sh,而您没有根据ls -al命令执行此操作的权限

-rw-r--r-- 1 davea staff 99 Mar  9 15:23 web/entrypoint.sh

有两种简单的解决方案:
  • 授予entrypoint.sh文件执行权限:
  • chmod a+x web/entrypoint.sh
  • 或者,如果您不想授予此权限,则可以将入口点更新为ENTRYPOINT ["bash", "/app/entrypoint.sh"]

  • 请注意,无论哪种情况,这都不是 docker-compose挂载的问题,而是 Dockerfile的问题,因此,在进行如下更改后,您将需要重建docker镜像
    docker-compose up -d --build

    关于django - 在我的Docker镜像中挂载了本地目录,但无法从该目录读取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60732306/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com