我第一次使用docker,我有点不能正常启动它。这是我的docker-compose.yml文件:
version: "3"
services:
mysql:
image: mysql
container_name: my-mysql
restart: on-failure
ports:
- 3306:3306
volumes:
- ./mysql_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: ""
MYSQL_USER: intranet
MYSQL_PASSWORD: ""
MYSQL_DATABASE: intranet
MYSQL_ALLOW_EMPTY_PASSWORD: yes
healthcheck:
test:
[
"CMD",
"mysqladmin",
"ping",
"-h",
"localhost",
"-u",
"root",
"-pmy-root-password",
]
interval: 10s
timeout: 5s
retries: 5
backend:
build:
context: .
dockerfile: Dockerfile
container_name: my-backend
restart: on-failure
volumes:
- .:/app
environment:
DATABASE_URL: mysql2://intranet@mysql:3306/intranet
SECRET_KEY: x
ports:
- 8000:8000
depends_on:
- mysql
command: ["./etc/entry", "web-prod"]
字符串
我在MySQL工作台中创建了数据库127.0.0.1:3306,名称为Intranet,代码为:
CREATE USER 'intranet'@'localhost';
CREATE DATABASE intranet;
GRANT ALL PRIVILEGES ON intranet.* TO 'intranet'@'localhost';
FLUSH PRIVILEGES;
型
我得到的dockerfile是这样的:
FROM python:3.7
RUN wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O /usr/local/bin/cloud_sql_proxy \
&& chmod +x /usr/local/bin/cloud_sql_proxy
RUN pip3 install poetry
ENV LC_ALL C.UTF-8
ENV LANG C.UTF-8
# -- Install Application into container:
WORKDIR /app
COPY pyproject.toml pyproject.toml
COPY poetry.lock poetry.lock
RUN poetry config virtualenvs.create false && poetry install
COPY . /app
ARG GIT_VERSION
ENV GIT_VERSION $GIT_VERSION
ENTRYPOINT ["/app/etc/entry"]
CMD ["web-prod"]
型
当运行docker-compose up时,我得到了这个错误:django.db.utils.OperationalError: (1045, "Access denied for user 'intranet'@'172.19.0.3' (using password: NO)")
尝试搜索这个,但没有任何帮助。我还将提供来自我的项目的自述文件:
需要安装:
- 诗歌
- email protected(https://stackoverflow.com/cdn-cgi/l/email-protection)
- Python 3.7
- 节点v16
后台
请确保在MySQL中创建了intranet
数据库。如果没有,您可能需要使用以下命令:
mysql -u root -p
CREATE USER 'intranet'@'localhost';
CREATE DATABASE intranet;
GRANT ALL PRIVILEGES ON intranet.* TO 'intranet'@'localhost';
FLUSH PRIVILEGES;
exit;
型
然后:
poetry install
个poetry shell
个export DATABASE_URL='mysql2://intranet@localhost:3306/intranet'
个export SECRET_KEY='x'
个./manage.py migrate
个./manage.py update_perms
个./manage.py createcachetable
./manage.py runserver
顺便说一句。我自己写码头撰写文件,这就是为什么我认为这是我的问题。我真的很感激的答案,告诉我一步一步地修复,谢谢
1条答案
按热度按时间xzv2uavs1#
更新:如果你有这个问题,请仔细检查你的项目是否使用postgres而不是mysql进行开发
正确的docker-compose文件:
字符串