I trying to build a Django project with docker-compose and MySQL, but when i run the "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
My Dockerfile:
FROM python:3
ENV PYTHONBUFFERD=1
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
My docker-compose.yml file:
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
This is such a cryptic error that i don't really now where to go. If someone can help me i would be very happy.
Thank you !
Avoid copying using an all encompassing pattern like .
(the dot) for copying the whole working directory.
For one, this will be different for every environment where this runs because it includes all hidden and local files, and not only those you expect (those that are tracked by your version system, eg).
Second, there might be links that point to other directories, so you might even end up copying a lot of stuff you definitely never wanted to have in your Dockerfile. Which is most probably what happens in your case.
.dockerignore
is a way to work against copying too much, but you should also try to copy more explicitly. This will also help others to understand what you want to achieve with this specific COPY
command in your Dockerfile.
tl;dr: the resulting docker image should contain only what it needs to run, and should have to change (contain anything different) only if the change is intentional.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.