php - Laravel cannot connect to dockerise database -
i created 3 containers (php-nginx-mysql) support default laravel project located on host machine.
when try connect db laravel error:
route::get('/', function () { dd(app\user::all()); return view('welcome'); });
sqlstate[hy000] [2002] php_network_getaddresses: getaddrinfo failed: name or service not known (sql: select *
users
)
here .env in laravel-5.3.16
db_connection=mysql db_host=127.0.0.1 db_port=33061 db_database=homestead db_username=homestead db_password=secret
and ansible-playbook:
--- - hosts: localhost environment: pythonpath: /usr/local/lib/python2.7/site-packages/ tasks: - name: currernt location command: pwd register: my_way - set_fact: host_dir="{{my_way.stdout}}" - name: create image nginx docker_image: path: /home/demaunt/jun/dock_click/engie dockerfile: engie.dockerfile name: engie_image - name: create image php docker_image: path: /home/demaunt/jun/dock_click/piha dockerfile: piha.dockerfile name: piha_image - name: run piha container docker_container: name: piha_cont image: piha_image volumes: - "/home/demaunt/dockjun/laravel-5.3.16:/var/www/wapclick" links: - diba_cont:db env: db_port: 3306 db_host: database - name: run engie container docker_container: name: engie_cont image: engie_image volumes_from: - piha_cont ports: - "8080:80" links: - piha_cont:app - name: run diba container docker_container: name: diba_cont image: mysql:5.6 env: mysql_database: homestead mysql_user: homestead mysql_password: secret mysql_root_password: secret ports: - 33061:3306
what more strange when run php artisan migrate succesfull mesage:
migration table created successfully. migrated: 2014_10_12_000000_create_users_table migrated: 2014_10_12_100000_create_password_resets_table
here containers running:
docker ps container id image command created status ports names e926382db347 engie_image "nginx -g 'daemon ..." 19 seconds ago 18 seconds 443/tcp, 0.0.0.0:8080->80/tcp engie_cont c9563c839e45 piha_image "docker-php-entryp..." 19 seconds ago 18 seconds 9000/tcp piha_cont 5de541049da2 mysql:5.6 "docker-entrypoint..." 20 seconds ago 19 seconds 0.0.0.0:33061->3306/tcp diba_cont
try "diba_cont" db_host should job. docker declare automatically dns rule name of container contact container
Comments
Post a Comment