Reputation: 21
How to fix Remainder of file ignored python: can't open file '//manage.py
': \[Errno 2\]
No such file or directory when use command docker-compose up
This is all my code, and I've also attached an image file.
dockerfile files
FROM python:3.10
ENV PYTHONUNBUFFERED 1
COPY requirements.txt .
RUN pip install -r requirements.txt
EXPOSE 8000
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
docker-compose.yml
:
version: '3.7'
services:
db:
image: mariadb:10
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
- MYSQL_ROOT_PASSWORD = mariadb
- MYSQL_DATABASE = mariadb
- MYSQL_USER = mariadb
- MYSQL_PASSWORD = mariadb
- MARIADB_ROOT_PASSWORD=mysecretpassword
ports:
- 3306:3306
volumes:
- "mysqldata:/var/lib/mysql"
web:
build:
context: .
dockerfile: Dockerfile
restart: always
command: python manage.py runserver 0.0.0.0:8000
environment:
- DATABASE_URL=mariadb+mariadbconnector://user:mariadb@db:3306/mariadb
ports:
- "8000:8000"
depends_on:
- db
adminer:
image: adminer
restart: always
ports:
- 8080:8080
depends_on:
- db
volumes:
mysqldata:
setting.py
:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mariadb',
'USER': 'mariadb',
'PASSWORD': 'mariadb',
'HOST': '127.0.0.1',
'PORT': 3306,
}
}
Upvotes: 1
Views: 849
Reputation: 159040
In your Dockerfile, you don't COPY
any of your application code in, just the requirements.txt
file. A typical setup copies the entire source tree in after installing package dependencies
# existing
COPY requirements.txt .
RUN pip install -r requirements.txt
# add missing
COPY ./ ./
You should also be able to see this if you docker-compose run web ls
, starting a temporary container with a different command; your source code just won't be there.
There are a couple of other small errors or cleanups that can improve this setup as well:
mysql
container, there are spaces around the equals signs in the environment:
block. Compose doesn't recognize this, so you set e.g. MYSQL_USER
(ending with a space) to mariadb
(starting with a space). Remove these spaces, so MYSQL_USER=mariadb
.'host': 'db'
.WORKDIR /app
.CMD
as the Compose command:
. I'd delete the command:
line.build:
since you have the default Dockerfile name and no other options; build: .
with only the directory name and not a mapping.Upvotes: 2