- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 docker 19.03.6、docker-compose 1.25.3 和 ubuntu 18。当我运行 docker-compose up
时Web 容器可以工作,但 mysql 容器无法访问。我能做什么?
问题可能出在mysqlclient包上吗?
我的Python代码:
db = MySQLdb.connect(host="localhost", user="root", passwd="password", db="DBM", port=3306)
注意:我已经尝试过 src_db_1 而不是 localhost!
Dockerfile:
FROM python:3.8
ENV PYTHONUNBUFFERED 1
RUN mkdir /api_rest_mix_1_0
WORKDIR /api_rest_mix_1_0
ADD requirements.txt /api_rest_mix_1_0/
RUN pip install --upgrade pip && pip install -r requirements.txt
ADD . /api_rest_mix_1_0/
Docker 组合:
version: '3'
services:
db:
image: mysql:5.7
ports:
- '3306:3306'
environment:
MYSQL_DATABASE: 'DBM'
MYSQL_USER: 'root'
MYSQL_PASSWORD: 'password'
MYSQL_ROOT_PASSWORD: 'password'
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/my_app_dir
ports:
- "8000:8000"
depends_on:
- db
需求.txt:
Django==3.0.3
mysqlclient==1.4.6
我的终端突击队:docker-compose up
我的命令的输出:
Creating network "src_default" with the default driver
Creating src_db_1 ... done
Creating src_web_1 ... done
Attaching to src_db_1, src_web_1
db_1 | 2020-02-19 11:23:18+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.29-1debian9 started.
db_1 | 2020-02-19 11:23:18+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db_1 | 2020-02-19 11:23:18+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.29-1debian9 started.
db_1 | 2020-02-19 11:23:18+00:00 [Note] [Entrypoint]: Initializing database files
db_1 | 2020-02-19T11:23:18.929128Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1 | 2020-02-19T11:23:22.350394Z 0 [Warning] InnoDB: New log files created, LSN=45790
db_1 | 2020-02-19T11:23:23.042973Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
db_1 | 2020-02-19T11:23:23.291068Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 3d632fc3-530a-11ea-9cd8-0242ac140002.
db_1 | 2020-02-19T11:23:23.361130Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
db_1 | 2020-02-19T11:23:24.557385Z 0 [Warning] CA certificate ca.pem is self signed.
web_1 | Watching for file changes with StatReloader
web_1 | Performing system checks...
web_1 |
web_1 | System check identified no issues (0 silenced).
web_1 | February 19, 2020 - 11:23:25
web_1 | Django version 3.0.3, using settings 'api_rest_mix_1_0.settings'
web_1 | Starting development server at http://0.0.0.0:8000/
web_1 | Quit the server with CONTROL-C.
db_1 | 2020-02-19T11:23:25.254876Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
db_1 | 2020-02-19 11:23:43+00:00 [Note] [Entrypoint]: Database files initialized
db_1 | 2020-02-19 11:23:43+00:00 [Note] [Entrypoint]: Starting temporary server
db_1 | 2020-02-19 11:23:43+00:00 [Note] [Entrypoint]: Waiting for server startup
db_1 | 2020-02-19T11:23:43.925550Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1 | 2020-02-19T11:23:43.927341Z 0 [Note] mysqld (mysqld 5.7.29) starting as process 81 ...
db_1 | 2020-02-19T11:23:43.932133Z 0 [Note] InnoDB: PUNCH HOLE support available
db_1 | 2020-02-19T11:23:43.932155Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1 | 2020-02-19T11:23:43.932160Z 0 [Note] InnoDB: Uses event mutexes
db_1 | 2020-02-19T11:23:43.932164Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
db_1 | 2020-02-19T11:23:43.932168Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
db_1 | 2020-02-19T11:23:43.932172Z 0 [Note] InnoDB: Using Linux native AIO
db_1 | 2020-02-19T11:23:43.932473Z 0 [Note] InnoDB: Number of pools: 1
db_1 | 2020-02-19T11:23:43.932591Z 0 [Note] InnoDB: Using CPU crc32 instructions
db_1 | 2020-02-19T11:23:43.934281Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
db_1 | 2020-02-19T11:23:43.946320Z 0 [Note] InnoDB: Completed initialization of buffer pool
db_1 | 2020-02-19T11:23:43.948809Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
db_1 | 2020-02-19T11:23:43.960693Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
db_1 | 2020-02-19T11:23:44.063103Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db_1 | 2020-02-19T11:23:44.063192Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db_1 | 2020-02-19T11:23:44.347746Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db_1 | 2020-02-19T11:23:44.348505Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
db_1 | 2020-02-19T11:23:44.348523Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
db_1 | 2020-02-19T11:23:44.348922Z 0 [Note] InnoDB: 5.7.29 started; log sequence number 2630649
db_1 | 2020-02-19T11:23:44.349095Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db_1 | 2020-02-19T11:23:44.349223Z 0 [Note] Plugin 'FEDERATED' is disabled.
db_1 | 2020-02-19T11:23:44.350675Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200219 11:23:44
db_1 | 2020-02-19T11:23:44.354928Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
db_1 | 2020-02-19T11:23:44.354950Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
db_1 | 2020-02-19T11:23:44.355643Z 0 [Warning] CA certificate ca.pem is self signed.
db_1 | 2020-02-19T11:23:44.355680Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
db_1 | 2020-02-19T11:23:44.393563Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1 | 2020-02-19T11:23:44.420138Z 0 [Note] Event Scheduler: Loaded 0 events
db_1 | 2020-02-19T11:23:44.420413Z 0 [Note] mysqld: ready for connections.
db_1 | Version: '5.7.29' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server (GPL)
db_1 | 2020-02-19 11:23:44+00:00 [Note] [Entrypoint]: Temporary server started.
web_1 | Internal Server Error: /api/statistics/4
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
web_1 | response = get_response(request)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
web_1 | response = self.process_exception_by_middleware(e, request)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
web_1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
web_1 | File "/api_rest_mix_1_0/api/views.py", line 171, in statistics
web_1 | json_response = stt_sex_status_total()
web_1 | File "/api_rest_mix_1_0/api/views.py", line 99, in stt_sex_status_total
web_1 | db = MySQLdb.connect(host="localhost", user="root", passwd="password", db="DBMix_hml", charset='utf8', use_unicode=True)
web_1 | File "/usr/local/lib/python3.8/site-packages/MySQLdb/__init__.py", line 84, in Connect
web_1 | return Connection(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.8/site-packages/MySQLdb/connections.py", line 179, in __init__
web_1 | super(Connection, self).__init__(*args, **kwargs2)
web_1 | MySQLdb._exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
web_1 | [19/Feb/2020 11:23:45] "GET /api/statistics/4 HTTP/1.1" 500 82444
web_1 | Internal Server Error: /api/statistics/4
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
web_1 | response = get_response(request)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
web_1 | response = self.process_exception_by_middleware(e, request)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
web_1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
web_1 | File "/api_rest_mix_1_0/api/views.py", line 171, in statistics
web_1 | json_response = stt_sex_status_total()
web_1 | File "/api_rest_mix_1_0/api/views.py", line 99, in stt_sex_status_total
web_1 | db = MySQLdb.connect(host="localhost", user="root", passwd="password", db="DBMix_hml", charset='utf8', use_unicode=True)
web_1 | File "/usr/local/lib/python3.8/site-packages/MySQLdb/__init__.py", line 84, in Connect
web_1 | return Connection(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.8/site-packages/MySQLdb/connections.py", line 179, in __init__
web_1 | super(Connection, self).__init__(*args, **kwargs2)
web_1 | MySQLdb._exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
web_1 | [19/Feb/2020 11:23:46] "GET /api/statistics/4 HTTP/1.1" 500 82444
web_1 | Internal Server Error: /api/statistics/4
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
web_1 | response = get_response(request)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
web_1 | response = self.process_exception_by_middleware(e, request)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
web_1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
web_1 | File "/api_rest_mix_1_0/api/views.py", line 171, in statistics
web_1 | json_response = stt_sex_status_total()
web_1 | File "/api_rest_mix_1_0/api/views.py", line 99, in stt_sex_status_total
web_1 | db = MySQLdb.connect(host="localhost", user="root", passwd="password", db="DBMix_hml", charset='utf8', use_unicode=True)
web_1 | File "/usr/local/lib/python3.8/site-packages/MySQLdb/__init__.py", line 84, in Connect
web_1 | return Connection(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.8/site-packages/MySQLdb/connections.py", line 179, in __init__
web_1 | super(Connection, self).__init__(*args, **kwargs2)
web_1 | MySQLdb._exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
web_1 | [19/Feb/2020 11:23:47] "GET /api/statistics/4 HTTP/1.1" 500 82444
web_1 | Internal Server Error: /api/statistics/4
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
web_1 | response = get_response(request)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
web_1 | response = self.process_exception_by_middleware(e, request)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
web_1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
web_1 | File "/api_rest_mix_1_0/api/views.py", line 171, in statistics
web_1 | json_response = stt_sex_status_total()
web_1 | File "/api_rest_mix_1_0/api/views.py", line 99, in stt_sex_status_total
web_1 | db = MySQLdb.connect(host="localhost", user="root", passwd="password", db="DBMix_hml", charset='utf8', use_unicode=True)
web_1 | File "/usr/local/lib/python3.8/site-packages/MySQLdb/__init__.py", line 84, in Connect
web_1 | return Connection(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.8/site-packages/MySQLdb/connections.py", line 179, in __init__
web_1 | super(Connection, self).__init__(*args, **kwargs2)
web_1 | MySQLdb._exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
web_1 | [19/Feb/2020 11:23:47] "GET /api/statistics/4 HTTP/1.1" 500 82444
web_1 | Internal Server Error: /api/statistics/4
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
web_1 | response = get_response(request)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
web_1 | response = self.process_exception_by_middleware(e, request)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
web_1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
web_1 | File "/api_rest_mix_1_0/api/views.py", line 171, in statistics
web_1 | json_response = stt_sex_status_total()
web_1 | File "/api_rest_mix_1_0/api/views.py", line 99, in stt_sex_status_total
web_1 | db = MySQLdb.connect(host="localhost", user="root", passwd="password", db="DBMix_hml", charset='utf8', use_unicode=True)
web_1 | File "/usr/local/lib/python3.8/site-packages/MySQLdb/__init__.py", line 84, in Connect
web_1 | return Connection(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.8/site-packages/MySQLdb/connections.py", line 179, in __init__
web_1 | super(Connection, self).__init__(*args, **kwargs2)
web_1 | MySQLdb._exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
web_1 | [19/Feb/2020 11:23:47] "GET /api/statistics/4 HTTP/1.1" 500 82444
db_1 | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
db_1 | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
web_1 | Internal Server Error: /api/statistics/4
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
web_1 | response = get_response(request)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
web_1 | response = self.process_exception_by_middleware(e, request)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
web_1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
web_1 | File "/api_rest_mix_1_0/api/views.py", line 171, in statistics
web_1 | json_response = stt_sex_status_total()
web_1 | File "/api_rest_mix_1_0/api/views.py", line 99, in stt_sex_status_total
web_1 | db = MySQLdb.connect(host="localhost", user="root", passwd="password", db="DBMix_hml", charset='utf8', use_unicode=True)
web_1 | File "/usr/local/lib/python3.8/site-packages/MySQLdb/__init__.py", line 84, in Connect
web_1 | return Connection(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.8/site-packages/MySQLdb/connections.py", line 179, in __init__
web_1 | super(Connection, self).__init__(*args, **kwargs2)
web_1 | MySQLdb._exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
web_1 | [19/Feb/2020 11:23:48] "GET /api/statistics/4 HTTP/1.1" 500 82444
db_1 | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
db_1 | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
db_1 | 2020-02-19 11:23:52+00:00 [Note] [Entrypoint]: Creating database DBMix_hml
db_1 | 2020-02-19 11:23:52+00:00 [Note] [Entrypoint]: Creating user root
db_1 | ERROR 1396 (HY000) at line 1: Operation CREATE USER failed for 'root'@'%'
src_db_1 exited with code 1
最佳答案
将host="localhost"更改为host="db",例如
db = MySQLdb.connect(host="db", user="root", passwd="password", db="DBM", port=3306)
docker-compose.yml
services:
db:
image: mysql:5.7
ports:
- '3306:3306'
environment:
MYSQL_DATABASE: 'DBM'
MYSQL_USER: 'root'
MYSQL_PASSWORD: 'password'
MYSQL_ROOT_PASSWORD: 'password'
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/my_app_dir
ports:
- "8000:8000"
depends_on:
- db
links: # <-- add this
- db # <-- add this
关于python - (2002, "Can' t 通过套接字 '/var/run/mysqld/mysqld.sock' (2) 连接到本地 MySQL 服务器”),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60299450/
我在使用 IdHTTP 客户端组件时遇到一般 Indy 错误结合 SOCKS5 代理服务器并使用 SSL。 如果我将 IdHTTP 组件与我的 SOCKS5 代理(和非 https URL)一起使用,
使用代理连接(HTTP 代理:10.3.100.207,端口 8080)。 使用 python 的 request 模块的 get 函数,得到以下错误: “无法从 socks://10.3.100.2
如何为我的应用程序添加 SOCKS 支持?我在哪里可以得到库? 最佳答案 来自 http://java.sun.com/javase/6/docs/technotes/guides/net/proxi
我正在设置一个安装和配置了 docker 的基础镜像,这样当我运行我的 jenkins 管道时我可以进行 anchor 扫描。我必须将 anchor 图像拉到 docker 图像中,因为我的管道在 d
我提供了一个工作客户端和服务器文件。客户端向服务器发送图片。当你注释掉时: data = sock.recv(1024) print("received: ",str(data,"UTF-8")) 图
为什么我的 SOCKS 代理代码抛出 SocketException: Malformed reply from SOCKS server?我试过在 URLConnection 或其他中设置,但这不起
您好,我刚刚下载了适用于 OS X 10.11 的 mysql 5.7.13,我在让 phpmyadmin 连接它时遇到问题。 我能够完全安装 mysql,打开 mysql 服务器并设置 root 密
我正在尝试从容器内部控制主机 docker 服务。 对于 Linux 主机和 Linux 容器,通常是这样完成的:docker run -it -v/var/run/docker.sock:/var/
我正在使用将执行 docker 命令(docker ps 等)的图像设置 kubernetes 部署。 我的 yaml 如下所示: kind: Deployment apiVersion: apps/
我使用 this guide 安装 docker .我正在使用 Distributor ID: Ubuntu Description: Ubuntu 13.10 Release: 13.1
我正在使用以下命令启动docker: /usr/bin/dockerd --bip=172.30.224.1/21 --ip-masq=false --mtu=1450 --containerd=/r
我刚注册到 Stack Overflow,因为从 2 天前开始我真的无法摆脱这个问题。我使用 Xampp。 所以,我正在关注这个 Laravel tutorial当我从终端输入项目目录或每个其他目录
首先,我发誓我已经查看了涉及此错误的每一个问题。几乎每个人提供的解决方案都是不同的,而且似乎没有人理解错误的系统原因。我和网络上遇到这个常见问题的许多人需要的是对实际出了什么问题的解释。 基本上,当我
Magento 显示“处理您的请求时出错” 尝试命令“sudo service mysqld restart”但启动失败 然后看到日志显示“SQLSTATE[HY000] [2002] 没有这样的文件
Ubuntu 15.04 64位,docker 1.6.1,用户在docker组中。 操作系统启动后,每个docker命令执行都会导致此错误: FATA[0000] Get http:///var/r
我的问题开始于我无法再以 root 身份登录我的 mysql 安装。我试图在没有打开密码的情况下运行 mysql...但是每当我运行命令时 # mysqld_safe --skip-grant-tab
我的问题开始于我在安装 mysql 时无法再以 root 身份登录。我试图在没有打开密码的情况下运行 mysql ......但是每当我运行命令时 # mysqld_safe --skip-grant
简单明了,谁能解释一下如何通过代理 (socks4/5) 连接到 mysql 服务器。最好通过 mysql 命令行(尽管在客户端中没有选项)。 如果无法通过 mysql 命令行,那么任何其他方法都可以
简单明了,谁能解释一下如何通过代理 (socks4/5) 连接到 mysql 服务器。最好通过 mysql 命令行(尽管在客户端中没有选项)。 如果无法通过 mysql 命令行,那么任何其他方法都可以
我试图通过与 SoX 中的脉冲响应进行卷积来应用混响。以下 shell 脚本完全符合我的要求: #!/usr/bin/env bash # # Convolve audio file with and
我是一名优秀的程序员,十分优秀!