I have a setup for docker with two containers: One is the php / apache service, and the other container is the database (mysql).
Here is my docker-compose.yml
version: '2' services: app: depends_on: - db links: - db:mysql build: . image: app ports: - "80:80" restart: always links: - db:db volumes: - ../:/var/www/html/ db: image: mysql:latest restart: unless-stopped volumes: - ./db_data:/var/lib/mysql - ./databaseDumps:/tmp/databaseDumps environment: MYSQL_USER: "myApp" MYSQL_PASSWORD: "root" MYSQL_ROOT_PASSWORD: "root" MYSQL_DATABASE: "myAppDatabase" MYSQL_ROOT_HOST: "%"
And here is my Dockerfile application:
FROM php:7-apache COPY prefilled_files/000-default.conf /etc/apache2/sites-available/000-default.conf RUN apt-get -qq update RUN apt-get -qq -y install libpng-dev curl git nano vim zip unzip mysql-client libmysqlclient-dev RUN curl -sS https:
The main problem is that the mysql database and application container work well, and I can connect to mysql database from application container through
$root@app : mysql -h db -u myApp -p
BUT
if I try to run composer install in my symfony project , the following error message will appear:
[Doctrine\DBAL\Driver\PDOException] SQLSTATE[HY000] [2002] Connection refused [PDOException] SQLSTATE[HY000] [2002] Connection refused
Here are my options for my application:
parameters: database_driver: pdo_mysql database_host: db database_port: 3306 database_name: myAppDatabase database_user: myApp database_password: root
Why is this happening? I read several forums and sites, but nothing helped. I tried the following solutions and nothing helped:
- clear symfony cache;)
- open 3306 in mysql container
- bind application and mysql container together
- delete all images and containers from my computer and reinstall everything.
- I tried on windows and on ubuntu 17.04. Same behavior
connecting to mysql container installing docker denies access, but docker works with the same image
Docker-compose wordpress mysql connection rejected
UPDATE:
I tried to access my database using a small php script from https://gist.github.com/chales/11359952 . PHP / My script can really connect to the database , so the problem should be in my composer install or in the doctrine or in my symfony configuration.
TL; DR
- 2 compile docker via docker compile
- I can access the database using the
mysql command in the application container, but not over composer install . Why?
php mysql docker symfony docker-compose
Rubinum
source share