【发布时间】:2021-12-25 18:08:56
【问题描述】:
在运行docker-compose up -d --build 后跟docker ps(检查图像)后,MySQL 图像不存在。
ping 我的 API 端点时,我收到此错误:SQLSTATE[HY000] [2002] No such file or directory (SQL: select count(*) as aggregate fro userswhereemail = test@test.com)
docker-compose.yml 文件中的数据库凭据与 .env 文件中的内容相匹配,仅供参考,因此我们可以排除这是可能的问题。
我强烈怀疑这是因为在运行 docker ps 时不存在 MySQL 映像。
为了纠正这个问题,我尝试运行 docker-compose up testApp - 它没有解决它,因为我运行了 docker ps 并且 MySQL 映像仍然没有显示
为什么会发生这种情况,我该如何解决它以便可以连接到本地 MySQL 数据库?
docker-compose.yml文件:
version: "3.7"
services:
app:
build:
args:
user: sammy
uid: 1000
context: ./
dockerfile: Dockerfile.dev
working_dir: /var/www/
environment:
- COMPOSER_MEMORY_LIMIT=-1
depends_on:
- db
volumes:
- ./:/var/www
networks:
- lahmi
testApp:
image: mysql:5.7
platform: linux/x86_64
environment:
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_USER: ${DB_USERNAME}
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata:/var/lib/mysql
- ./docker-compose/mysql/my.cnf:/etc/mysql/my.cnf
- ./docker-compose/mysql/init:/docker-entrypoint-initdb.d
ports:
- 3307:3306
networks:
- lahmi
nginx:
image: nginx:alpine
ports:
- 8005:80
depends_on:
- db
- app
volumes:
- ./:/var/www
- ./docker-compose/nginx:/etc/nginx/conf.d/
networks:
- lahmi
networks:
lahmi:
driver: bridge
volumes:
dbdata:
driver: local
这是docker-compose up testApp的输出:
[+] Running 1/0
⠿ Container testApp-testApp-1 Created 0.0s
Attaching to testApp-testApp-1
testApp-testApp-1 | 2021-11-13 23:04:40+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.36-1debian10 started.
testApp-testApp-1 | 2021-11-13 23:04:40+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
testApp-testApp-1 | 2021-11-13 23:04:40+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.36-1debian10 started.
testApp-testApp-1 | 2021-11-13 23:04:41+00:00 [ERROR] [Entrypoint]: MYSQL_USER="root", MYSQL_USER and MYSQL_PASSWORD are for configuring a regular user and cannot be used for the root user
testApp-testApp-1 | Remove MYSQL_USER="root" and use one of the following to control the root user password:
testApp-testApp-1 | - MYSQL_ROOT_PASSWORD
testApp-testApp-1 | - MYSQL_ALLOW_EMPTY_PASSWORD
testApp-testApp-1 | - MYSQL_RANDOM_ROOT_PASSWORD
testApp-testApp-1 exited with code 1
通过docker-compose logs记录日志:
testApp-testApp-1 |
testApp-testApp-1 | ERROR: mysqld failed while attempting to check config
testApp-testApp-1 | command was: "mysqld --verbose --help"
testApp-testApp-1 |
testApp-testApp-1 | mysqld: Error on realpath() on '/var/lib/mysql-files' (Error 2 - No such file or directory)
testApp-testApp-1 | 2021-11-13T23:57:57.676571Z 0 [ERROR] [MY-010095] [Server] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files
testApp-testApp-1 | 2021-11-13T23:57:57.690269Z 0 [ERROR] [MY-010119] [Server] Aborting
testApp-testApp-1 |
testApp-testApp-1 | ERROR: mysqld failed while attempting to check config
testApp-testApp-1 | command was: "mysqld --verbose --help"
testApp-testApp-1 |
testApp-testApp-1 | mysqld: Error on realpath() on '/var/lib/mysql-files' (Error 2 - No such file or directory)
testApp-testApp-1 | 2021-11-13T23:58:20.142446Z 0 [ERROR] [MY-010095] [Server] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files
testApp-app-1 | [13-Nov-2021 23:58:20] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
testApp-testApp-1 | 2021-11-13T23:58:20.156224Z 0 [ERROR] [MY-010119] [Server] Aborting
testApp-app-1 | [13-Nov-2021 23:58:20] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
testApp-app-1 | [13-Nov-2021 23:58:20] NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root
testApp-app-1 | [13-Nov-2021 23:58:20] NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root
testApp-app-1 | [13-Nov-2021 23:58:20] NOTICE: fpm is running, pid 1
testApp-app-1 | [13-Nov-2021 23:58:20] NOTICE: ready to handle connections
testApp-app-1 | 172.18.0.3 - 14/Nov/2021:00:01:42 +0000 "POST /index.php" 500
testApp-nginx-1 | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
testApp-nginx-1 | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
testApp-nginx-1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
testApp-nginx-1 | 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
testApp-nginx-1 | 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf differs from the packaged version
testApp-nginx-1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
testApp-nginx-1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
testApp-nginx-1 | /docker-entrypoint.sh: Configuration complete; ready for start up
testApp-nginx-1 | 2021/11/13 23:58:21 [notice] 1#1: using the "epoll" event method
testApp-nginx-1 | 2021/11/13 23:58:21 [notice] 1#1: nginx/1.21.4
testApp-nginx-1 | 2021/11/13 23:58:21 [notice] 1#1: built by gcc 10.3.1 20210424 (Alpine 10.3.1_git20210424)
testApp-nginx-1 | 2021/11/13 23:58:21 [notice] 1#1: OS: Linux 5.10.47-linuxkit
testApp-nginx-1 | 2021/11/13 23:58:21 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
testApp-nginx-1 | 2021/11/13 23:58:21 [notice] 1#1: start worker processes
testApp-nginx-1 | 2021/11/13 23:58:21 [notice] 1#1: start worker process 31
testApp-nginx-1 | 2021/11/13 23:58:21 [notice] 1#1: start worker process 32
testApp-nginx-1 | 172.18.0.1 - - [14/Nov/2021:00:01:44 +0000] "POST /api/register HTTP/1.1" 500 15495 "-" "PostmanRuntime/7.28.4"
【问题讨论】:
-
你是reposting吗?
-
@matiaslauriti 是的,很抱歉...如果您愿意,可以关闭此问题。我几乎整天都在苦苦挣扎,但还是有用的:(
-
@gp_sflover 这最初是我的问题:) 尽管我最后的评论说它有效,但事实证明它并没有因为 mysql docker 映像仍然丢失。这篇文章就在这里,你刚刚评论的那个,有更多的细节。
-
日志到底能告诉你什么?
docker-compose logs或docker logs <container> -
@Jaquarh 查看我对原始帖子的最新评论,我已经发布了
docker-compose logs:)
标签: php laravel docker debugging docker-compose