alterway / docker-php

Docker PHP
MIT License
99 stars 45 forks source link

Connecting to mysql within compose #4

Open ScreamingDev opened 7 years ago

ScreamingDev commented 7 years ago

Connecting to some other server shouldn't fail but actually it does. Can you please bring in the hostname resolv via the docker network?

I guess this is the problem here because dockers php:5.6 is able to connect to some other container. With your container I need to add a "links: mysql" in the docker-compose config. Dunno why.

version: '3'

services:
  php:
    build: .
    ports:
      - "8000:80"
    volumes:
      - ".:/var/www/html"
  mysql:
    image: mysql:5.7
    environment:
      - MYSQL_USER=foo
      - MYSQL_PASSWORD=foo
      - MYSQL_DATABASE=foo
      - MYSQL_ROOT_PASSWORD=
      - MYSQL_ALLOW_EMPTY_PASSWORD=true

Dockerfile

FROM alterway/php:5.4-apache

RUN apt-get update

RUN apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng12-dev \
    && docker-php-ext-install -j$(nproc) iconv mcrypt \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd

RUN docker-php-ext-install mysql

# Simple tasks at last
RUN apt install -y mysql-client

# Config
RUN a2enmod rewrite

config

define('DB_NAME', 'foo');
define('DB_USER', 'foo');
define('DB_PASSWORD', 'foo');
define('DB_HOST', 'mysql');