Docker 文件
FROM python:3.10-slim
ENV PYTHONUNBUFFERED=1
RUN apt-get update && apt-get install -y supervisor && apt-get upgrade -y \
&& apt-get install -y gcc libcurl4-gnutls-dev librtmp-dev libnss3 libnss3-dev wget cron pkg-config \
libmariadb-dev-compat libmariadb-dev build-essential \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt
COPY . /app/
EXPOSE 8000
Docker 撰写文件
version: '3.9'
services:
vineCal_db:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_USER: ${DB_USERNAME}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_DATABASE: ${DB_NAME}
volumes:
- data:/var/lib/mysql
ports:
- "3306:3306"
web:
build: .
command: gunicorn --bind 0.0.0.0:8000 --workers 3 vinecalc_server.wsgi:application
volumes:
- .:/app
env_file:
- .env
ports:
- "8000:8000"
depends_on:
- vineCal_db
networks:
- my_network
celery_worker:
build: .
entrypoint: celery
command: -A vinecalc_server worker --loglevel=info
volumes:
- .:/app
env_file:
- .env
depends_on:
- vineCal_db
networks:
- my_network
celery_beat:
build: .
entrypoint: celery
command: -A vinecalc_server beat --loglevel=info
volumes:
- .:/app
env_file:
- .env
depends_on:
- vineCal_db
networks:
- my_network
volumes:
data:
networks:
my_network:
错误日志
vinecalc-server-celery_worker-1 | Usage: celery [OPTIONS] COMMAND [ARGS]...
vinecalc-server-celery_worker-1 | Try 'celery --help' for help.
vinecalc-server-celery_beat-1 | Usage: celery [OPTIONS] COMMAND [ARGS]...
vinecalc-server-celery_worker-1 |
vinecalc-server-celery_worker-1 |
vinecalc-server-celery_beat-1 | Try 'celery --help' for help.
vinecalc-server-celery_beat-1 |
vinecalc-server-celery_beat-1 | Error: Invalid value for '-A' / '--app':
vinecalc-server-celery_beat-1 | Unable to load celery application.
vinecalc-server-celery_beat-1 | While trying to load the module vinecalc_server the following error occurred:
vinecalc-server-celery_beat-1 | Traceback (most recent call last):
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/celery/app/utils.py", line 389, in find_app
vinecalc-server-celery_beat-1 | found = sym.app
vinecalc-server-celery_beat-1 | AttributeError: module 'vinecalc_server' has no attribute 'app'
vinecalc-server-celery_beat-1 |
vinecalc-server-celery_beat-1 | During handling of the above exception, another exception occurred:
vinecalc-server-celery_beat-1 |
vinecalc-server-celery_beat-1 | Traceback (most recent call last):
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/celery/app/utils.py", line 394, in find_app
vinecalc-server-celery_beat-1 | found = sym.celery
vinecalc-server-celery_beat-1 | AttributeError: module 'vinecalc_server' has no attribute 'celery'
vinecalc-server-celery_beat-1 |
vinecalc-server-celery_beat-1 | During handling of the above exception, another exception occurred:
vinecalc-server-celery_beat-1 |
vinecalc-server-celery_beat-1 | Traceback (most recent call last):
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/celery/app/utils.py", line 383, in find_app
vinecalc-server-celery_beat-1 | sym = symbol_by_name(app, imp=imp)
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/kombu/utils/imports.py", line 64, in symbol_by_name
vinecalc-server-celery_beat-1 | return getattr(module, cls_name) if cls_name else module
vinecalc-server-celery_beat-1 | AttributeError: module 'vinecalc_server' has no attribute 'celery'
vinecalc-server-celery_beat-1 |
vinecalc-server-celery_beat-1 | During handling of the above exception, another exception occurred:
vinecalc-server-celery_beat-1 |
vinecalc-server-celery_beat-1 | Traceback (most recent call last):
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py", line 279, in ensure_connection
vinecalc-server-celery_beat-1 | self.connect()
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
vinecalc-server-celery_beat-1 | return func(*args, **kwargs)
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py", line 256, in connect
vinecalc-server-celery_beat-1 | self.connection = self.get_new_connection(conn_params)
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
vinecalc-server-celery_beat-1 | return func(*args, **kwargs)
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/django/db/backends/mysql/base.py", line 256, in get_new_connection
vinecalc-server-celery_beat-1 | connection = Database.connect(**conn_params)
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/MySQLdb/__init__.py", line 121, in Connect
vinecalc-server-celery_beat-1 | return Connection(*args, **kwargs)
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/MySQLdb/connections.py", line 195, in __init__
vinecalc-server-celery_beat-1 | super().__init__(*args, **kwargs2)
vinecalc-server-celery_beat-1 | MySQLdb.OperationalError: (2005, "Unknown server host 'vineCal_db' (-3)")
vinecalc-server-celery_beat-1 |
vinecalc-server-celery_beat-1 | The above exception was the direct cause of the following exception:
vinecalc-server-celery_beat-1 |
vinecalc-server-celery_beat-1 | Traceback (most recent call last):
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/celery/bin/celery.py", line 58, in convert
vinecalc-server-celery_beat-1 | return find_app(value)
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/celery/app/utils.py", line 401, in find_app
vinecalc-server-celery_beat-1 | return find_app(
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/celery/app/utils.py", line 386, in find_app
vinecalc-server-celery_beat-1 | sym = imp(app)
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/celery/utils/imports.py", line 109, in import_from_cwd
vinecalc-server-celery_beat-1 | return imp(module, package=package)
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
vinecalc-server-celery_beat-1 | return _bootstrap._gcd_import(name[level:], package, level)
vinecalc-server-celery_beat-1 | File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
vinecalc-server-celery_beat-1 | File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
vinecalc-server-celery_beat-1 | File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
vinecalc-server-celery_beat-1 | File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
vinecalc-server-celery_beat-1 | File "<frozen importlib._bootstrap_external>", line 883, in exec_module
vinecalc-server-celery_beat-1 | File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
vinecalc-server-celery_beat-1 | File "/app/vinecalc_server/celery.py", line 17, in <module>
vinecalc-server-celery_beat-1 | tenant_queues = [
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/django/db/models/query.py", line 400, in __iter__
vinecalc-server-celery_beat-1 | self._fetch_all()
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/django/db/models/query.py", line 1928, in _fetch_all
vinecalc-server-celery_beat-1 | self._result_cache = list(self._iterable_class(self))
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/django/db/models/query.py", line 91, in __iter__
vinecalc-server-celery_beat-1 | results = compiler.execute_sql(
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1572, in execute_sql
vinecalc-server-celery_beat-1 | cursor = self.connection.cursor()
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
vinecalc-server-celery_beat-1 | return func(*args, **kwargs)
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py", line 320, in cursor
vinecalc-server-celery_beat-1 | return self._cursor()
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py", line 296, in _cursor
vinecalc-server-celery_beat-1 | self.ensure_connection()
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
vinecalc-server-celery_beat-1 | return func(*args, **kwargs)
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py", line 278, in ensure_connection
vinecalc-server-celery_beat-1 | with self.wrap_database_errors:
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
vinecalc-server-celery_beat-1 | raise dj_exc_value.with_traceback(traceback) from exc_value
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py", line 279, in ensure_connection
vinecalc-server-celery_beat-1 | self.connect()
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
vinecalc-server-celery_beat-1 | return func(*args, **kwargs)
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py", line 256, in connect
vinecalc-server-celery_beat-1 | self.connection = self.get_new_connection(conn_params)
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
vinecalc-server-celery_beat-1 | return func(*args, **kwargs)
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/django/db/backends/mysql/base.py", line 256, in get_new_connection
vinecalc-server-celery_beat-1 | connection = Database.connect(**conn_params)
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/MySQLdb/__init__.py", line 121, in Connect
vinecalc-server-celery_beat-1 | return Connection(*args, **kwargs)
vinecalc-server-celery_beat-1 | File "/usr/local/lib/python3.10/site-packages/MySQLdb/connections.py", line 195, in __init__
vinecalc-server-celery_beat-1 | super().__init__(*args, **kwargs2)
vinecalc-server-celery_beat-1 | django.db.utils.OperationalError: (2005, "Unknown server host 'vineCal_db' (-3)")
同样的错误
vinecalc-server-celery_worker-1
真正的问题是最后一行
Unknown server host 'vineCal_db' (-3)
如果查看 Compose 文件,数据库容器没有
networks:
块,但其他容器有。 这意味着数据库容器连接到一个名为 default
自动创建的网络,其中其他容器仅连接到手动创建的 my_network
。 由于它们不在同一网络上,因此它们无法相互通信。
对于几乎所有 Compose 应用程序,Compose 自己创建的
default
网络就足够了,最简单的设置是删除整个文件中 networks:
块的 all。