未链接Drupal环境的Docker容器 [英] Docker containers for Drupal environment not linked

查看:60
本文介绍了未链接Drupal环境的Docker容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Docker并通过安装Drupal进行实验.该过程是创建2个容器,其中一个运行Apache,另一个运行MySQL.

I'm learning Docker and experimenting by installing Drupal. The process is to create 2 containers with one running Apache and the other running MySQL.

我有以下 docker-compose.yml 文件:

version: '3'
services:
  d8:
    container_name: d8
    image: drupal
    build: .
    ports:
      - "8585:80"
    links: 
      - d8mysql:mysql
  d8mysql:
    container_name: d8mysql
    image: mysql
    restart: always
    environment: 
      MYSQL_ROOT_PASSWORD: password
      MYSQL_PASSWORD: password
      MYSQL_DATABASE: drupal
      MYSQL_USER: user
    ports:
      - "3306:3306"

还有这个 Dockerfile :

FROM drupal:latest
FROM mysql:latest

WORKDIR /var/www/html

当我运行 docker-compose up 时,两个容器都已成功创建,我可以登录并与之交互.

When I run docker-compose up, both my containers are successfully created, I can login and interact with both.

问题是drupal站点未连接到数据库.在设置过程中,我提供了 d8mysql 部分中标识的数据库名称,用户名和密码.我确认数据库和用户在容器中,但 drupal无法连接.下面的屏幕截图:

The problem is the drupal site is not connected to the database. During the setup process, I supply the database name, user and password as identified in the d8mysql section. I confirmed the database and user are in the container but drupal can not connect. Screenshot below:

查看 d8 部分,我在链接中加入了mysql容器的参数-我的

Looking at the d8 section, I included links with an argument of the mysql container - which my research indicates should do the trick but doesn't.

我还检查了Apache容器的/etc/hosts 文件,但是它没有MySQL容器的条目,显然应该在该条目中以便于进行所需的连接.

I also checked the /etc/hosts file of the Apache container but it has no entry for the MySQL container which apparently should be there to facilitate the desired connection.

推荐答案

由于默认情况下尚未为 mysql 图像定义标签,因此暂时使用 latest 8.0.18 .

Since you have not defined tag for mysql image by default uses latest which for the time being is 8.0.18.

Mysql 8已更改其密码身份验证方法,这似乎导致drupal图像不兼容问题.参见 github问题.

Mysql 8 has changed its password authentication method which seems to cause incompatibility issues with drupal image. See github issue.

一种选择是按照上述github问题的建议安装 mysql_native_password 插件.我还没有测试过.

One option is to install mysql_native_password plugin as proposed to the github issue above. I haven't tested it though.

我已验证其正常工作的其他选项是对mysql映像使用较旧的docker标签,例如 mysql:5.7.28

The other options which I have validated it is working is to use an older docker tag for mysql image, e.g mysql:5.7.28

工作中 docker-compose :

version: '3'
services:
  d8:
    container_name: d8
    image: drupal
    ports:
      - "8585:80"
  d8mysql:
    container_name: d8mysql
    restart: always
    image: mysql:5.7.28
    environment: 
      MYSQL_ROOT_PASSWORD: password
      MYSQL_PASSWORD: password
      MYSQL_DATABASE: drupal
      MYSQL_USER: user
    # This is obsolete if you don't plan to connect to this db server from another machine outside docker network
    # ports:
    #   - "3306:3306"

注意:

  • 我没有使用您的 Dockerfile ,所以我删除了构建部分
  • 您的 Dockerfile 并没有做任何特别的事情.当定义多个 FROM 指令时,仅后者有效.
  • 我删除了链接部分,因为它是不需要.默认情况下, Docker-compose 创建一个隔离的网络,在堆栈启动时在其中添加容器.在此网络中,声明的服务名称(对于您的情况为 d8 d8mysql )充当域名.因此,容器可以通过该名称访问另一个容器.
  • I didn't use your Dockerfile, so I removed build section
  • Your Dockerfile does not do anything special. When defining multiple FROM instructions only the later is effective.
  • I removed link section as it is not required. Docker-compose by default creates an isolated network in which containers are added when stack starts. In this network, declared services names(d8,d8mysql for your case) act as domain names. Thus a container can access another via that name.

这篇关于未链接Drupal环境的Docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆