22

我在使用 laravel 5/mysql 应用程序访问我的 docker 容器中的管理员时遇到问题。我得到错误:

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name does not resolve

我的 docker-compose.yml :

version: '3'

services:

    votes_app:
        build:
            context: ./web
            dockerfile: Dockerfile.yml

        container_name: votes_app_container
        environment:
            - APACHE_RUN_USER=#1000
        volumes:
            - ${APP_PATH_HOST}:${APP_PTH_CONTAINER}
        ports:
            - 8081:80
        working_dir: ${APP_PTH_CONTAINER}


    votes_db:
        image: mysql:5.6.41
        container_name: votes_db_container

        restart: always
        environment: 
            MYSQL_ROOT_PASSWORD: 1
        volumes:
            - ${DB_PATH_HOST}:/var/lib/mysql


    votes_adminer:
        image: adminer
        container_name: votes_adminer_container
        restart: always
        ports:
            - 8082:8080
        links:
            - votes_db


    votes_composer:
        image: composer:1.6
        container_name: votes_composer_container
        volumes:
            - ${APP_PATH_HOST}:${APP_PTH_CONTAINER}
        working_dir: ${APP_PTH_CONTAINER}
        command: composer install --ignore-platform-reqs

我为应用程序和数据库容器提供了不同的端口。

在这里https://hub.docker.com/_/adminer/我发现:

与外部服务器一起使用 您可以使用 ADMINER_DEFAULT_SERVER 环境变量指定默认主机。如果您要连接到外部服务器或命名为默认 db 以外的 docker 容器,这将非常有用。

docker run -p 8080:8080 -e ADMINER_DEFAULT_SERVER=mysql adminer

在我的应用程序的控制台中,我运行命令

$ docker run -p 8089:8080 -e ADMINER_DEFAULT_SERVER=votes_db adminer 

在我的应用程序端口中未使用并且此命令无论如何都没有成功,因为我在尝试登录管理员https://imgur.com/a/4HCdC1W时遇到了同样的错误。

哪个是正确的方法?

修改块#2:

在我的 docker-compose.yml 中:

version: '3'

services:

    votes_app:
        build:
            context: ./web
            dockerfile: Dockerfile.yml

        container_name: votes_app_container
        environment:
            - APACHE_RUN_USER=#1000
        volumes:
            - ${APP_PATH_HOST}:${APP_PTH_CONTAINER}
        ports:
            - 8081:80
        working_dir: ${APP_PTH_CONTAINER}


    db:
        image: mysql:5.6.41
        restart: always
        environment: 
            MYSQL_ROOT_PASSWORD: 1
        volumes:
            - ${DB_PATH_HOST}:/var/lib/mysql


    adminer:
        image: adminer
        restart: always
        ports:
            - 8082:8080
        links:
            - db


    votes_composer:
        image: composer:1.6
        container_name: votes_composer_container
        volumes:
            - ${APP_PATH_HOST}:${APP_PTH_CONTAINER}
        working_dir: ${APP_PTH_CONTAINER}
        command: composer install --ignore-platform-reqs

我重建了应用程序,但未能登录到管理员:https ://imgur.com/a/JWVGfBA

我在操作系统的控制台中运行,指向其他未使用的 8089 端口:

$ docker run -p 8089:8080 -e ADMINER_DEFAULT_SERVER=db adminer
PHP 7.2.11 Development Server started at Thu Nov  1 07:00:46 2018
[Thu Nov  1 07:01:11 2018] ::ffff:172.17.0.1:34048 [200]: /
[Thu Nov  1 07:01:20 2018] ::ffff:172.17.0.1:34052 [302]: /
[Thu Nov  1 07:01:21 2018] ::ffff:172.17.0.1:34060 [403]: /?server=db&username=root

但再次错误登录到管理员到 8089 端口,但错误消息不同:

https://imgur.com/a/a8qM4bt

怎么了 ?

修改块#3:

我想是的,因为在我重建容器后,我进入了盒子并在控制台输出中看到了“root”:

$ docker-compose exec votes_app bash
root@a4aa907373f5:/var/www/html# ls -la
total 1063
drwxrwxrwx 1 root root   4096 Oct 27 12:01 .
drwxr-xr-x 1 root root   4096 Oct 16 00:11 ..
-rwxrwxrwx 1 root root    234 Oct 13 07:15 .editorconfig
-rwxrwxrwx 1 root root   1029 Oct 31 06:10 .env
-rwxrwxrwx 1 root root    651 Oct 13 07:15 .env.example
drwxrwxrwx 1 root root   4096 Nov  1 11:10 .git
-rwxrwxrwx 1 root root    111 Oct 13 07:15 .gitattributes
-rwxrwxrwx 1 root root    294 Oct 13 07:15 .gitignore
-rwxrwxrwx 1 root root   4356 Oct 13 07:15 1.txt
drwxrwxrwx 1 root root      0 Oct 13 07:15 __DOCS
drwxrwxrwx 1 root root      0 Oct 13 07:15 __SQL
drwxrwxrwx 1 root root   4096 Oct 13 07:15 app
-rwxrwxrwx 1 root root   1686 Oct 13 07:15 artisan                                                                                                                                                                     
drwxrwxrwx 1 root root      0 Oct 13 07:15 bootstrap                                                                                                                                                                   
-rwxrwxrwx 1 root root   2408 Oct 13 07:15 composer.json                                                                                                                                                               
-rwxrwxrwx 1 root root 200799 Oct 13 07:15 composer.lock                                                                                                                                                               
drwxrwxrwx 1 root root   4096 Oct 13 07:15 config                                                                                                                                                                      
drwxrwxrwx 1 root root   4096 Oct 13 07:15 database                                                                                                                                                                    
-rwxrwxrwx 1 root root  52218 Oct 17 05:25 db_1_err.txt                                                                                                                                                                
-rwxrwxrwx 1 root root 482562 Oct 13 07:15 package-lock.json                                                                                                                                                           
-rwxrwxrwx 1 root root   1168 Oct 13 07:15 package.json                                                                                                                                                                
-rwxrwxrwx 1 root root   1246 Oct 13 07:15 phpunit.xml                                                                                                                                                                 
drwxrwxrwx 1 root root   4096 Oct 13 07:15 public
-rwxrwxrwx 1 root root     66 Oct 13 07:15 readme.txt
drwxrwxrwx 1 root root      0 Oct 13 07:15 resources
drwxrwxrwx 1 root root   4096 Oct 13 07:15 routes
-rwxrwxrwx 1 root root    563 Oct 13 07:15 server.php
drwxrwxrwx 1 root root   4096 Oct 13 07:15 storage
drwxrwxrwx 1 root root      0 Oct 13 07:15 tests
drwxrwxrwx 1 root root   8192 Nov  1 13:05 vendor
-rwxrwxrwx 1 root root   1439 Oct 13 07:15 webpack.mix.js
-rwxrwxrwx 1 root root 261143 Oct 13 07:15 yarn.lock
root@a4aa907373f5:/var/www/html# echo $USER

root@a4aa907373f5:/var/www/html#  uname -a
Linux a4aa907373f5 4.15.0-36-generic #39-Ubuntu SMP Mon Sep 24 16:19:09 UTC 2018 x86_64 GNU/Linux

无论如何它可能是问题吗?

修改块#4

我重新制作了这个 docker,我设置了容器的默认名称(我想它会引起一些混乱)并设置 image: composer:1.8 latest version 所以在我的 docker-compose.yml 中:

version: '3.1'

services:

    web:

        build:
            context: ./web
            dockerfile: Dockerfile.yml

        environment:
            - APACHE_RUN_USER=#1000
        volumes:
            - ${APP_PATH_HOST}:${APP_PTH_CONTAINER}
        ports:
            - 8081:80
        working_dir: ${APP_PTH_CONTAINER}

    db:
        image: mysql:5.6.41
        restart: always
        environment: 
            MYSQL_ROOT_PASSWORD: 1
        volumes:
            - ${DB_PATH_HOST}:/var/lib/mysql

    adminer:
        image: adminer
        restart: always
        ports:
            - 8082:8080
        links:
            - db

    composer:
        image: composer:1.8
        volumes:
            - ${APP_PATH_HOST}:${APP_PTH_CONTAINER}
        working_dir: ${APP_PTH_CONTAINER}
        command: composer install --ignore-platform-reqs

在 web/Dockerfile.yml 中:

FROM php:7.2-apache

RUN apt-get update -y && apt-get install -y libpng-dev nano

RUN docker-php-ext-install \
    pdo_mysql \
    && a2enmod \
    rewrite

但无论如何,在重建项目并使用 http://127.0.0.1:8082 url 连接到管理员后,我得到了错误:

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Try again

PS:我有其他 laravel 5.0/php:5.6 / image: composer:1.6 / mcrypt 在我笔记本电脑的同一本地服务器上安装了 docker 项目,这对我来说没问题,我可以输入管理员并可以从这个应用程序登录到 db。这个 docker 项目有文件:

码头工人-compose.yml:

version: '3.1'

services:

    web:
        build:
            context: ./web
            dockerfile: Dockerfile.yml

        environment:
            - APACHE_RUN_USER=#1000
        volumes:
            - ${APP_PATH_HOST}:${APP_PTH_CONTAINER}
        ports:
            - 8085:80
        working_dir: ${APP_PTH_CONTAINER}


    db:
        image: mysql:5.5.62
        restart: always
        environment: 
            MYSQL_ROOT_PASSWORD: 1
        volumes:
            - ${DB_PATH_HOST}:/var/lib/mysql


    adminer:
        image: adminer
        restart: always
        ports:
            - 8086:8080
        links:
            - db


    composer:
        image: composer:1.6
        volumes:
            - ${APP_PATH_HOST}:${APP_PTH_CONTAINER}
        working_dir: ${APP_PTH_CONTAINER}
        command: composer install --ignore-platform-reqs

和 Dockerfile.yml :

FROM php:5.6-apache

RUN apt-get update -y && apt-get install -y libpng-dev   nano  libmcrypt-dev

RUN docker-php-ext-install \
    pdo_mysql \
    mcrypt \
    && a2enmod \
    rewrite

这个问题是一些 php 7.2 的特定功能吗(比如缺少一些包?)

修改块#5: 定义:

phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - 8082:8080
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: 1

运行http://127.0.0.1:8082/我在浏览器中遇到错误:

This site can’t be reached The webpage at http://127.0.0.1:8082/ might be temporarily down or it may have moved permanently to a new web address.
ERR_SOCKET_NOT_CONNECTED

在尝试应用程序网址http://127.0.0.1:8081/public/时出现错误:

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution 

修改块#6: 我在 docker-compose.yml 中使用 phpmyadmin 重新制作:

version: '3.1'

services:

#  docker run -p 8089:8080 -e ADMINER_DEFAULT_SERVER=db adminer
    web:

        # env_file:
        #     - ./mysql.env

        build:
            context: ./web
            dockerfile: Dockerfile.yml

        environment:
            - APACHE_RUN_USER=#1000
        volumes:
            - ${APP_PATH_HOST}:${APP_PTH_CONTAINER}
        ports:
            - 8081:80
        working_dir: ${APP_PTH_CONTAINER}


    db:
        image: mysql:5.6.41
        restart: always
        environment: 
            MYSQL_ROOT_PASSWORD: 1
        volumes:
            - ${DB_PATH_HOST}:/var/lib/mysql


    phpmyadmin:
        depends_on:
          - db
        image: phpmyadmin/phpmyadmin
        restart: always
        ports:
          - 8082:80
        environment:
          PMA_HOST: db
          MYSQL_ROOT_PASSWORD: 1

    composer:
        image: composer:1.8
        volumes:
            - ${APP_PATH_HOST}:${APP_PTH_CONTAINER}
        working_dir: ${APP_PTH_CONTAINER}
        command: composer install --ignore-platform-reqs

但试图登录到 phpMyAdmin

http://127.0.0.1:8082

我得到了同样的错误:https ://imgur.com/a/cGeudI6

我也有端口:

$ docker ps
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS                          PORTS                            NAMES
471de34926b9        phpmyadmin/phpmyadmin    "/run.sh supervisord…"   41 minutes ago      Up 41 minutes                   9000/tcp, 0.0.0.0:8082->80/tcp   votes_docker_phpmyadmin_1
226fcdbeeb25        mysql:5.6.41             "docker-entrypoint.s…"   41 minutes ago      Restarting (1) 49 seconds ago                                    votes_docker_db_1
1cb1efb10561        votes_docker_web         "docker-php-entrypoi…"   41 minutes ago      Up 41 minutes                   0.0.0.0:8081->80/tcp             votes_docker_web_1
d6718cd16256        adminer                  "entrypoint.sh docke…"   13 hours ago        Up About an hour                0.0.0.0:8088->8080/tcp           ads_docker_adminer_1
1928a54e1d66        mysql:5.5.62             "docker-entrypoint.s…"   13 hours ago        Up About an hour                3306/tcp                         ads_docker_db_1
e43b2a1e9cc7        adminer                  "entrypoint.sh docke…"   6 days ago          Up About an hour                0.0.0.0:8086->8080/tcp           youtubeapi_demo_adminer_1
47a034fca5a2        mysql:5.5.62             "docker-entrypoint.s…"   6 days ago          Up About an hour                3306/tcp                         youtubeapi_demo_db_1
3dcc1a4ce8f0        adminer                  "entrypoint.sh docke…"   6 weeks ago         Up About an hour                0.0.0.0:8083->8080/tcp           lprods_adminer_container
933d9fffaf76        postgres:9.6.10-alpine   "docker-entrypoint.s…"   6 weeks ago         Up About an hour                0.0.0.0:5433->5432/tcp           lprods_db_container

  MODIFIED BLOCK # 7  我不确定我可以提供哪些调试信息,但似乎日志记录有一些警告。它们很关键吗?我可以提供哪些附加调试信息?

serge@serge:/mnt/_work_sdb8/wwwroot/lar/DockerApps/votes_docker$ docker-compose up -d --build              
Creating network "votes_docker_default" with the default driver 
Building web 
Step 1/3 : FROM php:7.2-apache 
 ---> cf1a377ba77f 
Step 2/3 : RUN apt-get update -y && apt-get install -y libpng-dev nano 
 ---> Using cache 
 ---> 2c4bce73e8cc 
Step 3/3 : RUN docker-php-ext-install     pdo_mysql     && a2enmod     rewrite 
 ---> Using cache 
 ---> 241c9bf59ac0 
Successfully built 241c9bf59ac0 
Successfully tagged votes_docker_web:latest 
Creating votes_docker_composer_1   ... done 
Creating votes_docker_web_1        ... done 
Creating votes_docker_db_1       ... done 
Creating votes_docker_phpmyadmin_1 ... done 
serge@serge:/mnt/_work_sdb8/wwwroot/lar/DockerApps/votes_docker$ clear 
serge@serge:/mnt/_work_sdb8/wwwroot/lar/DockerApps/votes_docker$ docker logs --tail=20  votes_docker_web_1 
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.20.0.4. Set the 'ServerName' directive globally to suppress this message 
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.20.0.4. Set the 'ServerName' directive globally to suppress this message 
[Wed Dec 26 12:26:34.113194 2018] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.25 (Debian) PHP/7.2.11 configured -- resuming normal operations 
[Wed Dec 26 12:26:34.113247 2018] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND' 
serge@serge:/mnt/_work_sdb8/wwwroot/lar/DockerApps/votes_docker$ docker logs --tail=20  votes_docker_db_1 
2018-12-26 12:26:43 1 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX' 
2018-12-26 12:26:43 1 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET' 
2018-12-26 12:26:43 1 [Note] Shutting down plugin 'INNODB_CMPMEM' 
2018-12-26 12:26:43 1 [Note] Shutting down plugin 'INNODB_CMP_RESET' 
2018-12-26 12:26:43 1 [Note] Shutting down plugin 'INNODB_CMP' 
2018-12-26 12:26:43 1 [Note] Shutting down plugin 'INNODB_LOCK_WAITS' 
2018-12-26 12:26:43 1 [Note] Shutting down plugin 'INNODB_LOCKS' 
2018-12-26 12:26:43 1 [Note] Shutting down plugin 'INNODB_TRX' 
2018-12-26 12:26:43 1 [Note] Shutting down plugin 'BLACKHOLE' 
2018-12-26 12:26:43 1 [Note] Shutting down plugin 'ARCHIVE' 
2018-12-26 12:26:43 1 [Note] Shutting down plugin 'MRG_MYISAM' 
2018-12-26 12:26:43 1 [Note] Shutting down plugin 'MyISAM' 
2018-12-26 12:26:43 1 [Note] Shutting down plugin 'MEMORY' 
2018-12-26 12:26:43 1 [Note] Shutting down plugin 'CSV' 
2018-12-26 12:26:43 1 [Note] Shutting down plugin 'sha256_password' 
2018-12-26 12:26:43 1 [Note] Shutting down plugin 'mysql_old_password' 
2018-12-26 12:26:43 1 [Note] Shutting down plugin 'mysql_native_password' 
2018-12-26 12:26:43 1 [Note] Shutting down plugin 'binlog' 
2018-12-26 12:26:43 1 [Note] mysqld: Shutdown complete 

serge@serge:/mnt/_work_sdb8/wwwroot/lar/DockerApps/votes_docker$ docker logs --tail=20  votes_docker_composer_1    
> @php artisan package:discover 
Discovered Package: aloha/twilio 
Discovered Package: barryvdh/laravel-debugbar 
Discovered Package: beyondcode/laravel-dump-server 
Discovered Package: cviebrock/eloquent-sluggable 
Discovered Package: davejamesmiller/laravel-breadcrumbs 
Discovered Package: fideloper/proxy 
Discovered Package: intervention/image 
Discovered Package: itsgoingd/clockwork 
Discovered Package: jrean/laravel-user-verification 
Discovered Package: laravel/tinker 
Discovered Package: laravelcollective/html 
Discovered Package: mews/captcha 
Discovered Package: nesbot/carbon 
Discovered Package: nunomaduro/collision 
Discovered Package: proengsoft/laravel-jsvalidation 
Discovered Package: rap2hpoutre/laravel-log-viewer 
Discovered Package: themsaid/laravel-mail-preview 
Discovered Package: yajra/laravel-datatables-oracle 
Package manifest generated successfully. 
serge@serge:/mnt/_work_sdb8/wwwroot/lar/DockerApps/votes_docker$ docker logs --tail=20  votes_docker_phpmyadmin_1 
phpMyAdmin not found in /var/www/html - copying now... 
Complete! phpMyAdmin has been successfully copied to /var/www/html 
/usr/lib/python2.7/site-packages/supervisor/options.py:461: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); 
you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security. 
  'Supervisord is running as root and it is searching ' 
2018-12-26 12:26:35,973 CRIT Supervisor is running as root.  Privileges were not dropped because no user is specified in the config file.  If you intend to run as root, you can set user=root in the config file to av
oid this message. 
2018-12-26 12:26:35,973 INFO Included extra file "/etc/supervisor.d/nginx.ini" during parsing 
2018-12-26 12:26:35,973 INFO Included extra file "/etc/supervisor.d/php.ini" during parsing 
2018-12-26 12:26:35,984 INFO RPC interface 'supervisor' initialized 
2018-12-26 12:26:35,984 CRIT Server 'unix_http_server' running without any HTTP authentication checking 
2018-12-26 12:26:35,984 INFO supervisord started with pid 1 
2018-12-26 12:26:36,986 INFO spawned: 'php-fpm' with pid 23 
2018-12-26 12:26:36,988 INFO spawned: 'nginx' with pid 24 
[26-Dec-2018 12:26:37] NOTICE: fpm is running, pid 23 
[26-Dec-2018 12:26:37] NOTICE: ready to handle connections 
2018-12-26 12:26:38,094 INFO success: php-fpm entered RUNNING state, process has stayed up for > than 1 seconds (startsecs) 
2018-12-26 12:26:38,095 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

怎么了 ?

谢谢!

4

6 回答 6

7

尝试使用 phpMyAdmin :)

version: '3.2'
services:
    db:
        image: mysql:5.7

        restart: always
        environment:
          MYSQL_ROOT_PASSWORD: myUserPass
          MYSQL_DATABASE: mydb
          MYSQL_USER: myUser
          MYSQL_PASSWORD: myUser

    phpmyadmin:
        depends_on:
          - db
        image: phpmyadmin/phpmyadmin
        restart: always
        ports:
          - 8088:80
        environment:
          PMA_HOST: db
          MYSQL_ROOT_PASSWORD: myUserPass
于 2018-12-25T11:04:06.530 回答
6

我遇到了同样的问题,然后我发现 Adminer 应用程序中服务器地址的默认值是“db”,这与我的 MySQL 容器的服务名称不匹配。 在此处输入图像描述

在此处输入图像描述

于 2021-08-29T18:54:10.707 回答
3

您可以在 https://hub.docker.com/_/adminer/中看到它

例子

version: '3.1'

services:

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080

  db:
    image: mysql:5.6
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example
于 2018-10-31T09:36:58.027 回答
2

您的设置问题是由于环境变量DB_PATH_HOST。您已经在撰写文件中设置了所有内容。但在运行 docker-compose 之前,您应该定义环境变量DB_PATH_HOST。由于未定义环境变量,因此会引发错误。有关环境变量的更多详细信息及其在 Docker 中的优先级,请参阅此内容。

所以你应该做的是,在启动 docker 容器之前,你应该通过在 compose 文件中定义环境变量或在运行 docker-compose 之前在 shell 中将其导出为 shell 变量来定义环境变量,或者应该使用 env 文件或使用 ENV 指令在泊坞窗文件中。(这些是定义环境变量的所有可能方法,我已经列出了所有这些方法,首先出现的方法具有优先权。有关更多信息,请参阅此)。

所以正确的 docker-compose.yml文件应该如下。

version: '3.2'
services:
   db:
        image: mysql:5.6.41
        restart: always
        environment: 
            MYSQL_ROOT_PASSWORD: 1
            DB_PATH_HOST: /tmp/mysql #this is the host location where mysql data will be stored.
        volumes:
            - ${DB_PATH_HOST}:/var/lib/mysql

    phpmyadmin:
        depends_on:
          - db
        image: phpmyadmin/phpmyadmin
        restart: always
        ports:
          - 8082:80
        environment:
          PMA_HOST: db
          MYSQL_ROOT_PASSWORD: 1

现在进入下一点,我从您的讨论中看到,您已经得出结论,从 db 容器中删除卷可以解决您的问题。但实际上不是。如何?

首先让我解释一下为什么这里使用音量。我的mysql生成的数据应该存储在某个地方。默认情况下,Docker 以非持久模式运行容器,这意味着当容器关闭/杀死时,正在运行的 docker conatiner 生成的所有数据都将被删除。因此,为了持久化(存储/保存)数据,我们使用卷。docker 中使用了不同类型的卷。我鼓励您阅读 docker 的存储文档以获取更多详细信息。这里使用的卷类型是绑定挂载,即,您将主机目录绑定到 docker 目录,并且 docker 将所有数据直接存储在主机中,这样即使 docker 容器被关闭,数据仍然被保留。

因此,如果您不在 mysql 中使用卷,则无论您做什么,所有 db 更改都会在容器停止时丢失。

奖励积分:

  1. 默认情况下 MySQL 容器不允许远程连接。因此,如果您想从除 phpmyadmin 之外的任何其他地方访问 mysql。您必须允许远程连接。
  2. 因为我们在这里保存数据,所以只有在你第一次启动 mysqll 容器时才会设置 root 密码。从下次开始,root 密码环境变量将被忽略。
  3. 如果您主要使用 docker exec 登录到 docker 容器,您可以看到您将成为 root。这是因为每当您使用 Dockerfile 创建 docker 容器时,docker build除非docker-compose build您指定创建和使用新用户Dockerfile的指令,否则 docker将以 root 用户身份运行所有内容。
  4. 现在,每当您运行上述撰写文件时。您可以看到 mysql 数据位置的所有权将被更改。这是因为每当您将主机目录挂载到 docker 时,Docker 都会根据该容器的 Dockerile 定义根据用户和组更改文件权限。这里mysql 定义了一个名为的用户和组mysqluid 和 gid 是 999。因此 /tmp/mysql 将拥有 999:999 作为所有权。如果这些 id 与系统中的任何其他用户帐户映射,那么每当您在主机中执行 ls -al 时,您将看到这些名称而不是 id。如果 id 未映射,那么您将直接看到 id。
  5. 我以/tmp/mysql作为 mysql 数据目录为例。请不要使用相同的,因为 /tmp 中的数据将在系统重新启动时被删除。
于 2018-12-29T14:28:46.777 回答
0

将容器名称更改为db for mysql image 对我来说有所不同你可以在https://hub.docker.com/_/adminer/中看到它

服务:数据库:图像:mysql:5.6

于 2021-07-22T09:42:53.400 回答
0

该问题已得到解答,但在此处添加我对类似问题的解决方案以供参考。

向我的 docker-compose phpmyadmin/adminer 服务块添加一个“链接”参数为我解决了这个问题,基于数据库块的服务名称实际上也是上面回答的示例中使用的 db 的假设。这个链接使得在 phpmyadmin 登录界面中使用 'db' 作为主机成为可能,它将连接。

links:
  - db:db
于 2020-09-03T07:00:45.323 回答