在构建步骤中无法连接到Docker容器“ php”中的mysql

时间:2019-02-09 06:28:42

标签: php mysql docker

我尝试创建docker映像来部署我的应用程序,我选择mysql,php,nginx作为我的开发环境。是我的docker-compose文件

version: '3.0'
services:
  nginx:
    image: nginx:1.15
    container_name: nginx
    ports:
      - 8080:80
    volumes:
      - ./nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf
    links:
      - php
  php:
    build: ./
    container_name: php
  mysql:
    image: mysql:5.7
    container_name: mysql
    links:
      - php
    ports:
      - 3306:3306
    environment:
      MYSQL_ROOT_PASSWORD: 1111
      MYSQL_DATABASE: magento
      MYSQL_USER: manager
      MYSQL_PASSWORD: 1111
    volumes:
      - ./mysql:/var/lib/mysql
  adminer:
    image: adminer
    restart: always
    ports:
      - 8000:8080
    links:
      - mysql

和Dockerfile

FROM php:7.2-fpm

RUN apt-get update && apt-get install -y \
curl \
wget \
git \
vim \
libfreetype6-dev \
libjpeg62-turbo-dev \
libxslt-dev \
libicu-dev \
libmcrypt-dev \
libpng-dev \
libxml2-dev

RUN docker-php-ext-install bcmath \
gd \
intl \
soap \
xsl \
zip \
pdo_mysql

WORKDIR /var/www/html

RUN curl -sS https://getcomposer.org/installer | php -- --install- 
dir=/usr/local/bin --filename=composer
RUN composer config -g http-basic.repo.magento.com -a 
5310458a34d580de1700dfe826ff19a1 255059b03eb9d30604d5ef52fca7465d
RUN composer create-project --repository- 
url=https://repo.magento.com/ magento/project-community-edition .

RUN php bin/magento setup:install \
--base-url="http://localhost/" \
--db-host="mysql" \
--db-name="magento" \
--db-user="manager" \
--db-password="1111" \
--backend-frontname="admin" \
--admin-firstname="admin" \
--admin-lastname="admin" \
--admin-email="admin@admin.com" \
--admin-user="admin" \
--admin-password="admin123" \
--language="en_US" \
--currency="USD" \
--timezone="America/New_York" \
--use-rewrites="1"

我运行docker-compose up --build后,在步骤RUN php bin/magento setup:install...上出错了

getaddrinfo failed: Name or service not known

In InstallCommand.php line 264:

Parameter validation failed 

我知道与db的错误连接,如果我删除此步骤并在php容器中运行他的容器,一切都会好的。请帮助我,如何在构建步骤连接到我的数据库?

0 个答案:

没有答案