django - Docker-compose 使用 django 和 mysql 构建错误
问题描述
我试图用 docker-compose 和 MySQL 构建一个 Django 项目,但是当我运行“docker
db uses an image, skipping
Building with native build. Learn about native build in Compose here:
Building web
Sending build context to Docker daemon 22.02kB
Step 6/6 : COPY . /code/
---> 2f42d48fb668
Successfully built 2f42d48fb668
Successfully tagged djangonew_web:latest
Traceback (most recent call last):
File "docker-compose", line 3, in <module>
File "compose/cli/main.py", line 80, in main
File "compose/cli/main.py", line 192, in perform_command
File "compose/metrics/decorator.py", line 18, in wrapper
File "compose/cli/main.py", line 369, in build
File "compose/project.py", line 521, in build
File "compose/project.py", line 503, in build_service
File "compose/service.py", line 1131, in build
File "compose/progress_stream.py", line 22, in stream_output
File "compose/utils.py", line 50, in split_buffer
File "compose/utils.py", line 26, in stream_as_text
File "compose/service.py", line 1894, in build
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpjwyh07ql'
[16684] Failed to execute script docker-compose
我的 Dockerfile:
FROM python:3
ENV PYTHONBUFFERD=1
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
我的 docker-compose.yml 文件:
version: "3.9"
services:
db:
image: mysql
environment:
- MYSQL_DB=mysql_test
- MYSQL_USER=test
- MYSQL_PASSWORD=test
- MYSQL_ROOT_PASSWORD=test
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
这是一个如此神秘的错误,我现在真的不知道该去哪里。如果有人可以帮助我,我会很高兴。
谢谢 !
解决方案
避免使用像(点)这样的包罗万象的模式.
来复制整个工作目录。
一方面,这对于运行它的每个环境都会有所不同,因为它包括所有隐藏和本地文件,而不仅仅是您期望的那些(例如,由您的版本系统跟踪的那些)。
其次,可能存在指向其他目录的链接,因此您甚至可能最终复制了很多您绝对不想在 Dockerfile 中包含的内容。这很可能是您的情况。
.dockerignore
是一种防止过度复制的方法,但您也应该尝试更明确地复制。这也将帮助其他人了解您希望COPY
在 Dockerfile 中使用此特定命令实现的目标。
tl; dr:生成的 docker 映像应该只包含它需要运行的内容,并且只有在有意更改时才应该更改(包含任何不同的内容)。
推荐阅读
- c++ - setjmp/longjmp 在发布和调试中的不同行为
- r - 在ggplot2中使用for循环保存图形
- c - C - 未知类型名称
- docker - 几次 POST 请求后 uwsgi 超时
- colors - OnPressed 将 activeColor 设置为列表的按钮,并将 inactiveColor 设置为其他 btns - Flutter
- azure - 适用于 Windows Server 2012 R2 Datacenter VM 上的 SQL Server 2014 在 Azure 上的 Terraform 脚本
- javascript - Angular Firestore:使用 where 子句的集合查询的正确语法是什么?
- email - SMTP relay not working on PHPMailer 6.0.5
- c - 如何在 C 中打印水平和垂直直方图?
- ios - 当应用程序从后台执行重新启动时,Crashlytics 日志文件是否包含日志?