我有以下 docker-compose.yml
文件:
version: '3'
services:
maria_service:
build: ./db_maria
restart: always
environment:
MYSQL_DATABASE: mariadb
MYSQL_USER: joel
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
volumes:
- ./db:/var/lib/mysql
drupal_service:
build: ./website
restart: always
ports:
- 8080:80
volumes:
- /var/www/html/modules
- /var/www/html/profiles
- /var/www/html/themes
# this takes advantage of the feature in Docker that a new anonymous
# volume (which is what we're creating here) will be initialized with the
# existing content of the image at the same location
- /var/www/html/sites
depends_on:
- maria_service
这是我的工作目录:
这是drupal dockerfile,我正在做的就是拉出drupal图像:
这是mariadb dockerfile:
它自动生成这个“db”子文件夹,如下图所示:
我的问题是每当我在localhost:8080的drupal UI上输入mariadb时,它会抛出以下错误:
更新
根据@Tarun Lalwani的回答,我的问题是,在Drupal UI中,我会输入我的用户名,密码和数据库名称,但如果你在Drupal屏幕截图中展开了高级选项,你会看到HOSTNAME是指向“localhost”时,它应该指向mariadb数据库服务器的实际主机名,在DOCKER WORLD中,正在运行的容器的主机名是ITS SERVICE NAME,即在docker-compose.yml文件中看到的“mariadb_service” - 看截图。希望我不是唯一能够帮助他人的新手,感谢Tarun Lalwani!