Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3924

Docker or symfony missconfig. error SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known

$
0
0

How can I fix this? Is this a miss config in docker-compose or maybe is a miss config in PHP-fpm or I should do something in simfony env. I really don't know what to change. If I call doctrine from console require localhost as host and when the browser use pdo need to have host as MySQL (the docker name)

Very strange issue. After hours of debugging I find out why doctrine:migrations:migrate failed

C:\Users\Admin\Development\lemp\www\web>php bin/console doctrine:migrations:migrate 

returning the following error:

An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known.

I found out that runing migration is working if I replace the host in the .env file:

DATABASE_URL=mysql://dummy:dummy@mysql:3306/dummy?serverVersion=5.7 with DATABASE_URL=mysql://dummy:dummy@localhost:3306/dummy?serverVersion=5.7

But a new problem arose. The http://localhost:8080/ require the old env with mysql to run: DATABASE_URL=mysql://dummy:dummy@mysql:3306/dummy?serverVersion=5.7

You can find all the config file in my public repo: https://github.com/dumitriucristian/nginx-server

This is my docker-compose.yml content

version: '3'
# https://linoxide.com/containers/setup-lemp-stack-docker/
# http://www.inanzzz.com/index.php/post/zpbw/creating-a-simple-php-fpm-nginx-and-mysql-application-with-docker-compose
#https://www.pascallandau.com/blog/php-php-fpm-and-nginx-on-docker-in-windows-10/
#http://www.inanzzz.com/index.php/post/0e95/copying-symfony-application-into-docker-container-with-multi-stage-builds
#https://learn2torials.com/a/dockerize-reactjs-app
#https://knplabs.com/en/blog/how-to-dockerise-a-symfony-4-project
services:
  nginx:
    build:
     context: .
     dockerfile: docker/nginx/Dockerfile
    ports:
      - "8080:80"
    volumes:
     - ./nginx-server/logs:/var/log/nginx
     - ./nginx-server/default.conf:/etc/nginx/conf.d/default.conf
     - ./www/:/srv/www
    depends_on:
     - phpfpm

  phpfpm:
    build:
       context: .
       dockerfile: docker/phpfpm/Dockerfile
    ports:
     - "9000:9000"
    volumes:
     - ./www:/srv/www
     - ./docker/phpfpm/default.conf:/usr/local/etc/php-fpm.d/default.conf
    environment:
      MYSQL_USER: "dummy"
      MYSQL_PASSWORD: "dummy"

  mysql:
    image: mysql:5.7
    ports:
        - 3306:3306
    depends_on:
        - phpfpm
    environment:
        MYSQL_ROOT_PASSWORD: "dummy"
        MYSQL_DATABASE: "dummy"
        MYSQL_USER: "dummy"
        MYSQL_PASSWORD: "dummy"

  app:
    build:
      context: .
      dockerfile: docker/app/Dockerfile
    environment:
      - NODE_ENV=test
    command: npm run start
    ports:
      - 3000:3000
    volumes:
      - ./app:/app

nginx\Dockerfile

FROM nginx:latest
RUN apt-get update && apt-get install -y unzip zlib1g-dev git curl libmcrypt-dev bcrypt nano man

COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

WORKDIR /usr/src
RUN mkdir -p web
COPY ./www/web /usr/src/web

RUN PATH=$PATH:/web/vendor/bin:bin


EXPOSE 9000
EXPOSE 80

phpfpm\Dockerfile

FROM php:7.4.0-fpm-alpine

RUN apk update \
 && apk add --no-cache $PHPIZE_DEPS \
    git \
    zip \
    unzip \
 && docker-php-ext-install \
    opcache \
    pdo_mysql \
 && docker-php-ext-enable \
    opcache \
 && rm -rf \
    /var/cache/apk/* \
    /var/lib/apt/lists/*

COPY ./docker/phpfpm/php.ini /usr/local/etc/php/conf.d/php.override.ini
COPY ./nginx-server/default.conf /usr/local/etc/php-fpm.d/default.conf``

and nginx default.conf

  server {
        listen       0.0.0.0:80;
        listen       [::]:80 default_server;
        server_name  _;
        root  /srv/www/web/public;
        index index.htm index.html index.php ;

        default_type text/html;

        location ~* \.php$ {
            try_files $uri $uri/ /index.php;
            fastcgi_pass   phpfpm:9000;
           #fastcgi_pass unix:/run/php/php7.4-fpm.sock;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
           #fastcgi_pass unix:/tmp/phpcgi.socket;
            fastcgi_param SCRIPT_NAME  $fastcgi_script_name;
            fastcgi_index  index.php;
            include fastcgi_params;
        }

    }

Thanks, I am new to dev-ops but I try.


Viewing all articles
Browse latest Browse all 3924

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>