使用 phpmyadmin docker 时无法连接到 mysql docker

使用 phpmyadmin docker 时无法连接到 mysql docker

我刚刚开始使用 docker,可能有点入门了,但我找到了一篇文章,其中解释了如何安装 coldfusion(通过命令框运行)和 mysql。这个 docker compose 运行得很好。我想到添加 phpmyadmin,这样我就可以使用它来连接到 mysql。

供参考,原文在这里:https://cfswarm.inleague.io/part3-docker-in-development/part3-running-docker

所以我修改了 phpmyadmin 中的 docker compose yml pull

    version: '3.6'  # if no version is specificed then v1 is assumed. Recommend v2 minimum
volumes:
  sql-data:
networks:
  cfswarm-simple:
secrets:
  cfconfig:
    file: ./config/cfml/cfconfig.json

services:       
  cfswarm-mysql:        # a friendly name. this is also DNS name inside network
    image: mysql:5.7
    container_name: cfswarm-mysql
    environment:
      MYSQL_ROOT_PASSWORD: 'myAwesomePassword'
      MYSQL_DATABASE: 'cfswarm-simple-dev'
      MYSQL_ROOT_HOST: '%'
      MYSQL_LOG_CONSOLE: 'true'
    volumes:    
      - type: volume
        source: sql-data
        target: /var/lib/mysql
    ports: 
      - 3306:3306
    networks:
        - cfswarm-simple
  cfswarm-cfml:
    image: ortussolutions/commandbox:alpine
    container_name: cfswarm-cfml
    volumes:
      - type: bind
        source: ./app-one
        target: /app
    ports: 
      - 8081:8080        
    env_file:
      - ./config/cfml/simple-cfml.env
    secrets:
      - source: cfconfig # this isn't really a secret but non-stack deploys don't support configs so let's make it one
        target: cfconfig.json
    networks:
        - cfswarm-simple
    depends_on:
      - cfswarm-mysql
      - cfswarm-nginx
  cfswarm-two-cfml:
    image: ortussolutions/commandbox:alpine
    container_name: cfswarm-two-cfml
    volumes:
      - type: bind
        source: ./app-two
        target: /app
    env_file:
      - ./config/cfml/simple-cfml.env
    secrets:
      - source: cfconfig # this isn't really a secret but non-stack deploys don't support configs so let's make it one
        target: cfconfig.json
    depends_on:
      - cfswarm-mysql
      - cfswarm-nginx
    networks:
        - cfswarm-simple
  **phpmyadmin:
        image: phpmyadmin/phpmyadmin:latest
        container_name: phpmyadmin
        restart: always
        environment:
          PMA_HOST: cfswarm-mysql
          PMA_USER: root
          PMA_PASSWORD: 'myAwesomePassword'
        ports:
             - "8082:80"**       
  cfswarm-nginx:
    image: nginx
    command: [nginx-debug, '-g', 'daemon off;']
    container_name: cfswarm-nginx
    ports:
      - 80:80
      - 443:443
    volumes:
      - type: bind
        source: ./app-one
        target: /var/www/app-one
      - type: bind
        source: ./app-two
        target: /var/www/app-two
      - type: bind
        source: ./nginx/
        target: /etc/nginx
    networks:
      - cfswarm-simple

因此,在第 63 行,我添加了 phpymyadmin 的拉取功能,它似乎可以工作,它确实在端口 8082 上应答,但它给了我一个错误:

MySQL 说:文档

Cannot connect: invalid settings.
 mysqli::real_connect(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution
 mysqli::real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution
 phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.

有一件事我无法完成,那就是在 cfswarm-simple 的网络中添加。当我尝试在端口下方添加行(第 72 行)时,尝试启动 docker compose 时会收到错误。

现在,我希望能够使用 phpmyadmin 的 docker 连接到 mysql docker。

短暂性脑缺血发作

答案1

我发现这是空格问题。确保任何新条目与之前使用的空格相匹配。

相关内容