Failed to connect to MySQL: No such file or directory

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I wrote this docker-compose project. The docker-compose.yml looks like this:



version: '3.1'

services:
db:
image: mysql
restart: always
environment:
- MYSQL_DATABASE=mgsv
- MYSQL_USER=mgsv_user
- MYSQL_PASSWORD=mgsvpass
- MYSQL_ROOT_PASSWORD=mysql123
volumes:
- ./mysql:/docker-entrypoint-initdb.d

www:
build: ./mGSV
restart: always
ports:
- 8080:80


The index.php looks like this:



<?php
echo "Hello World!";
//mysqli_connect("localhost","my_user","my_password","my_db");
$con = mysqli_connect("localhost","mgsv_user","mgsvpass","mgsv");

// Check connection
if (mysqli_connect_errno())

echo "Failed to connect to MySQL: " . mysqli_connect_error();

else
echo "done";

?>


And the Dockerfile is based on a PHP container and looks like this.



FROM php:5-apache

RUN apt-get update && apt-get install -y --no-install-recommends
openjdk-7-jdk
maven
git
&& rm -rf /var/lib/apt/lists/*

RUN docker-php-source extract
&& docker-php-ext-install mysql mysqli pdo pdo_mysql
&& docker-php-source delete

RUN cd /var/www/html/ && git clone https://github.com/qunfengdong/mGSV.git

# Move the folder 'mgsv' to DocumentRoot of Apache web server. By default, the DocumentRoot of Apache is /var/www/ (speak to the system administrator to know the exact DocumentRoot).
RUN cd /var/www/html/mGSV
&& mkdir tmp
&& chmod -R 777 tmp

RUN cd /var/www/html/mGSV && sed -i.bak "s|'gsv'|'mgsv_user'|" lib/settings.php
&& sed -i.bak "s|$database_pass = ''|$database_pass = 'mgsvpass'|" lib/settings.php
&& sed -i.bak "s|cas-qshare.cas.unt.edu|localhost|" lib/settings.php

RUN cp /var/www/html/mGSV/Arial.ttf /usr/share/fonts/truetype/

RUN cd /var/www/html/mGSV/ws
&& tar -xzf mgsv-ws-server.tar.gz

RUN cd /var/www/html/mGSV/ws/mgsv-ws-server
&& mvn package

RUN cp -f /var/www/html/mGSV/ws/mgsv-ws-server/target/ws-server-1.0RC1-jar-with-dependencies.jar /var/www/html/mGSV/ws/

RUN cd /var/www/html/mGSV/ws
&& echo "mgsv_upload_url=http://localhost/mgsv" > config.properties
&& echo "ws_publish_url=http://localhost:8081/MGSVService" >> config.properties
&& java -jar ws-server-1.0RC1-jar-with-dependencies.jar &

COPY ./index.php /var/www/html/
RUN a2enmod rewrite


When using http://localhost:8080/ this is the output which I got:



Hello World!
Warning: mysqli_connect(): (HY000/2002): No such file or directory in /var/www/html/index.php on line 4
Failed to connect to MySQL: No such file or directory


What did I miss?



Thank you in advance.







share|improve this question
























    up vote
    2
    down vote

    favorite












    I wrote this docker-compose project. The docker-compose.yml looks like this:



    version: '3.1'

    services:
    db:
    image: mysql
    restart: always
    environment:
    - MYSQL_DATABASE=mgsv
    - MYSQL_USER=mgsv_user
    - MYSQL_PASSWORD=mgsvpass
    - MYSQL_ROOT_PASSWORD=mysql123
    volumes:
    - ./mysql:/docker-entrypoint-initdb.d

    www:
    build: ./mGSV
    restart: always
    ports:
    - 8080:80


    The index.php looks like this:



    <?php
    echo "Hello World!";
    //mysqli_connect("localhost","my_user","my_password","my_db");
    $con = mysqli_connect("localhost","mgsv_user","mgsvpass","mgsv");

    // Check connection
    if (mysqli_connect_errno())

    echo "Failed to connect to MySQL: " . mysqli_connect_error();

    else
    echo "done";

    ?>


    And the Dockerfile is based on a PHP container and looks like this.



    FROM php:5-apache

    RUN apt-get update && apt-get install -y --no-install-recommends
    openjdk-7-jdk
    maven
    git
    && rm -rf /var/lib/apt/lists/*

    RUN docker-php-source extract
    && docker-php-ext-install mysql mysqli pdo pdo_mysql
    && docker-php-source delete

    RUN cd /var/www/html/ && git clone https://github.com/qunfengdong/mGSV.git

    # Move the folder 'mgsv' to DocumentRoot of Apache web server. By default, the DocumentRoot of Apache is /var/www/ (speak to the system administrator to know the exact DocumentRoot).
    RUN cd /var/www/html/mGSV
    && mkdir tmp
    && chmod -R 777 tmp

    RUN cd /var/www/html/mGSV && sed -i.bak "s|'gsv'|'mgsv_user'|" lib/settings.php
    && sed -i.bak "s|$database_pass = ''|$database_pass = 'mgsvpass'|" lib/settings.php
    && sed -i.bak "s|cas-qshare.cas.unt.edu|localhost|" lib/settings.php

    RUN cp /var/www/html/mGSV/Arial.ttf /usr/share/fonts/truetype/

    RUN cd /var/www/html/mGSV/ws
    && tar -xzf mgsv-ws-server.tar.gz

    RUN cd /var/www/html/mGSV/ws/mgsv-ws-server
    && mvn package

    RUN cp -f /var/www/html/mGSV/ws/mgsv-ws-server/target/ws-server-1.0RC1-jar-with-dependencies.jar /var/www/html/mGSV/ws/

    RUN cd /var/www/html/mGSV/ws
    && echo "mgsv_upload_url=http://localhost/mgsv" > config.properties
    && echo "ws_publish_url=http://localhost:8081/MGSVService" >> config.properties
    && java -jar ws-server-1.0RC1-jar-with-dependencies.jar &

    COPY ./index.php /var/www/html/
    RUN a2enmod rewrite


    When using http://localhost:8080/ this is the output which I got:



    Hello World!
    Warning: mysqli_connect(): (HY000/2002): No such file or directory in /var/www/html/index.php on line 4
    Failed to connect to MySQL: No such file or directory


    What did I miss?



    Thank you in advance.







    share|improve this question






















      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I wrote this docker-compose project. The docker-compose.yml looks like this:



      version: '3.1'

      services:
      db:
      image: mysql
      restart: always
      environment:
      - MYSQL_DATABASE=mgsv
      - MYSQL_USER=mgsv_user
      - MYSQL_PASSWORD=mgsvpass
      - MYSQL_ROOT_PASSWORD=mysql123
      volumes:
      - ./mysql:/docker-entrypoint-initdb.d

      www:
      build: ./mGSV
      restart: always
      ports:
      - 8080:80


      The index.php looks like this:



      <?php
      echo "Hello World!";
      //mysqli_connect("localhost","my_user","my_password","my_db");
      $con = mysqli_connect("localhost","mgsv_user","mgsvpass","mgsv");

      // Check connection
      if (mysqli_connect_errno())

      echo "Failed to connect to MySQL: " . mysqli_connect_error();

      else
      echo "done";

      ?>


      And the Dockerfile is based on a PHP container and looks like this.



      FROM php:5-apache

      RUN apt-get update && apt-get install -y --no-install-recommends
      openjdk-7-jdk
      maven
      git
      && rm -rf /var/lib/apt/lists/*

      RUN docker-php-source extract
      && docker-php-ext-install mysql mysqli pdo pdo_mysql
      && docker-php-source delete

      RUN cd /var/www/html/ && git clone https://github.com/qunfengdong/mGSV.git

      # Move the folder 'mgsv' to DocumentRoot of Apache web server. By default, the DocumentRoot of Apache is /var/www/ (speak to the system administrator to know the exact DocumentRoot).
      RUN cd /var/www/html/mGSV
      && mkdir tmp
      && chmod -R 777 tmp

      RUN cd /var/www/html/mGSV && sed -i.bak "s|'gsv'|'mgsv_user'|" lib/settings.php
      && sed -i.bak "s|$database_pass = ''|$database_pass = 'mgsvpass'|" lib/settings.php
      && sed -i.bak "s|cas-qshare.cas.unt.edu|localhost|" lib/settings.php

      RUN cp /var/www/html/mGSV/Arial.ttf /usr/share/fonts/truetype/

      RUN cd /var/www/html/mGSV/ws
      && tar -xzf mgsv-ws-server.tar.gz

      RUN cd /var/www/html/mGSV/ws/mgsv-ws-server
      && mvn package

      RUN cp -f /var/www/html/mGSV/ws/mgsv-ws-server/target/ws-server-1.0RC1-jar-with-dependencies.jar /var/www/html/mGSV/ws/

      RUN cd /var/www/html/mGSV/ws
      && echo "mgsv_upload_url=http://localhost/mgsv" > config.properties
      && echo "ws_publish_url=http://localhost:8081/MGSVService" >> config.properties
      && java -jar ws-server-1.0RC1-jar-with-dependencies.jar &

      COPY ./index.php /var/www/html/
      RUN a2enmod rewrite


      When using http://localhost:8080/ this is the output which I got:



      Hello World!
      Warning: mysqli_connect(): (HY000/2002): No such file or directory in /var/www/html/index.php on line 4
      Failed to connect to MySQL: No such file or directory


      What did I miss?



      Thank you in advance.







      share|improve this question












      I wrote this docker-compose project. The docker-compose.yml looks like this:



      version: '3.1'

      services:
      db:
      image: mysql
      restart: always
      environment:
      - MYSQL_DATABASE=mgsv
      - MYSQL_USER=mgsv_user
      - MYSQL_PASSWORD=mgsvpass
      - MYSQL_ROOT_PASSWORD=mysql123
      volumes:
      - ./mysql:/docker-entrypoint-initdb.d

      www:
      build: ./mGSV
      restart: always
      ports:
      - 8080:80


      The index.php looks like this:



      <?php
      echo "Hello World!";
      //mysqli_connect("localhost","my_user","my_password","my_db");
      $con = mysqli_connect("localhost","mgsv_user","mgsvpass","mgsv");

      // Check connection
      if (mysqli_connect_errno())

      echo "Failed to connect to MySQL: " . mysqli_connect_error();

      else
      echo "done";

      ?>


      And the Dockerfile is based on a PHP container and looks like this.



      FROM php:5-apache

      RUN apt-get update && apt-get install -y --no-install-recommends
      openjdk-7-jdk
      maven
      git
      && rm -rf /var/lib/apt/lists/*

      RUN docker-php-source extract
      && docker-php-ext-install mysql mysqli pdo pdo_mysql
      && docker-php-source delete

      RUN cd /var/www/html/ && git clone https://github.com/qunfengdong/mGSV.git

      # Move the folder 'mgsv' to DocumentRoot of Apache web server. By default, the DocumentRoot of Apache is /var/www/ (speak to the system administrator to know the exact DocumentRoot).
      RUN cd /var/www/html/mGSV
      && mkdir tmp
      && chmod -R 777 tmp

      RUN cd /var/www/html/mGSV && sed -i.bak "s|'gsv'|'mgsv_user'|" lib/settings.php
      && sed -i.bak "s|$database_pass = ''|$database_pass = 'mgsvpass'|" lib/settings.php
      && sed -i.bak "s|cas-qshare.cas.unt.edu|localhost|" lib/settings.php

      RUN cp /var/www/html/mGSV/Arial.ttf /usr/share/fonts/truetype/

      RUN cd /var/www/html/mGSV/ws
      && tar -xzf mgsv-ws-server.tar.gz

      RUN cd /var/www/html/mGSV/ws/mgsv-ws-server
      && mvn package

      RUN cp -f /var/www/html/mGSV/ws/mgsv-ws-server/target/ws-server-1.0RC1-jar-with-dependencies.jar /var/www/html/mGSV/ws/

      RUN cd /var/www/html/mGSV/ws
      && echo "mgsv_upload_url=http://localhost/mgsv" > config.properties
      && echo "ws_publish_url=http://localhost:8081/MGSVService" >> config.properties
      && java -jar ws-server-1.0RC1-jar-with-dependencies.jar &

      COPY ./index.php /var/www/html/
      RUN a2enmod rewrite


      When using http://localhost:8080/ this is the output which I got:



      Hello World!
      Warning: mysqli_connect(): (HY000/2002): No such file or directory in /var/www/html/index.php on line 4
      Failed to connect to MySQL: No such file or directory


      What did I miss?



      Thank you in advance.









      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 23 at 1:27









      user3523406

      477




      477




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          I believe the issue here is that localhost is not your database host. If that PHP script is running in the "www" docker container, localhost most likely does not have a listening MySQL server. IIRC, the "file not found" error from mysqli is due to not finding the MySQL socket on localhost. I also do not see that you are exposing any ports for the "db" image, so I am not sure how "www" is supposed to connect to a database running inside it.



          You would want to find what the address to the "db" docker container is, and what port it is listening on, then reference that in your mysqli_connect() function. An easier method, if you have a recent version of docker, would be to add your containers to the same Docker network and reference them by name.



          EDIT: Docker Networking



          You should read up on the networking feature in the official documentation as it is very useful. You can probably use the following docker-compose.yml (not tested):



          version: '3.1'

          services:
          db:
          image: mysql
          restart: always
          environment:
          - MYSQL_DATABASE=mgsv
          - MYSQL_USER=mgsv_user
          - MYSQL_PASSWORD=mgsvpass
          - MYSQL_ROOT_PASSWORD=mysql123
          volumes:
          - ./mysql:/docker-entrypoint-initdb.d
          networks:
          - web-db-net

          www:
          build: ./mGSV
          restart: always
          ports:
          - 8080:80
          networks:
          - web-db-net

          networks:
          web-db-net:


          Then change your connect line to refer to the db container by name (you would also need to specify port if not using the MySQL default, 3306):



          $con = mysqli_connect("db","mgsv_user","mgsvpass","mgsv");


          EDIT2: fixed docker-compose.yml so that networks actually works






          share|improve this answer






















          • I'm running docker-ce 18.03. How would it be possible to add the containers to the same Docker network and reference them by name?
            – user3523406
            Mar 23 at 4:16










          • I made an edit to show some docker networking
            – GracefulRestart
            Mar 23 at 18:19










          • Thank you but I got ERROR: In file './docker-compose.yml', network must be a mapping, not a string.. What did I miss?
            – user3523406
            Mar 24 at 8:43










          • as I mentioned, it was not tested. I just tested it and noticed my mistake. In the networks key, put a colon (:) at the end of the network name to make it a mapping. i have edited the code in my answer to reflect what I just tested.
            – GracefulRestart
            Mar 24 at 21:58










          • Thank you, but I got again Warning: mysqli_connect(): (HY000/2002): No such file or directory in /var/www/html/index.php on line 4 Failed to connect to MySQL: No such file or directory. Any idea?
            – user3523406
            Mar 24 at 23:59










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f432976%2ffailed-to-connect-to-mysql-no-such-file-or-directory%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          I believe the issue here is that localhost is not your database host. If that PHP script is running in the "www" docker container, localhost most likely does not have a listening MySQL server. IIRC, the "file not found" error from mysqli is due to not finding the MySQL socket on localhost. I also do not see that you are exposing any ports for the "db" image, so I am not sure how "www" is supposed to connect to a database running inside it.



          You would want to find what the address to the "db" docker container is, and what port it is listening on, then reference that in your mysqli_connect() function. An easier method, if you have a recent version of docker, would be to add your containers to the same Docker network and reference them by name.



          EDIT: Docker Networking



          You should read up on the networking feature in the official documentation as it is very useful. You can probably use the following docker-compose.yml (not tested):



          version: '3.1'

          services:
          db:
          image: mysql
          restart: always
          environment:
          - MYSQL_DATABASE=mgsv
          - MYSQL_USER=mgsv_user
          - MYSQL_PASSWORD=mgsvpass
          - MYSQL_ROOT_PASSWORD=mysql123
          volumes:
          - ./mysql:/docker-entrypoint-initdb.d
          networks:
          - web-db-net

          www:
          build: ./mGSV
          restart: always
          ports:
          - 8080:80
          networks:
          - web-db-net

          networks:
          web-db-net:


          Then change your connect line to refer to the db container by name (you would also need to specify port if not using the MySQL default, 3306):



          $con = mysqli_connect("db","mgsv_user","mgsvpass","mgsv");


          EDIT2: fixed docker-compose.yml so that networks actually works






          share|improve this answer






















          • I'm running docker-ce 18.03. How would it be possible to add the containers to the same Docker network and reference them by name?
            – user3523406
            Mar 23 at 4:16










          • I made an edit to show some docker networking
            – GracefulRestart
            Mar 23 at 18:19










          • Thank you but I got ERROR: In file './docker-compose.yml', network must be a mapping, not a string.. What did I miss?
            – user3523406
            Mar 24 at 8:43










          • as I mentioned, it was not tested. I just tested it and noticed my mistake. In the networks key, put a colon (:) at the end of the network name to make it a mapping. i have edited the code in my answer to reflect what I just tested.
            – GracefulRestart
            Mar 24 at 21:58










          • Thank you, but I got again Warning: mysqli_connect(): (HY000/2002): No such file or directory in /var/www/html/index.php on line 4 Failed to connect to MySQL: No such file or directory. Any idea?
            – user3523406
            Mar 24 at 23:59














          up vote
          1
          down vote













          I believe the issue here is that localhost is not your database host. If that PHP script is running in the "www" docker container, localhost most likely does not have a listening MySQL server. IIRC, the "file not found" error from mysqli is due to not finding the MySQL socket on localhost. I also do not see that you are exposing any ports for the "db" image, so I am not sure how "www" is supposed to connect to a database running inside it.



          You would want to find what the address to the "db" docker container is, and what port it is listening on, then reference that in your mysqli_connect() function. An easier method, if you have a recent version of docker, would be to add your containers to the same Docker network and reference them by name.



          EDIT: Docker Networking



          You should read up on the networking feature in the official documentation as it is very useful. You can probably use the following docker-compose.yml (not tested):



          version: '3.1'

          services:
          db:
          image: mysql
          restart: always
          environment:
          - MYSQL_DATABASE=mgsv
          - MYSQL_USER=mgsv_user
          - MYSQL_PASSWORD=mgsvpass
          - MYSQL_ROOT_PASSWORD=mysql123
          volumes:
          - ./mysql:/docker-entrypoint-initdb.d
          networks:
          - web-db-net

          www:
          build: ./mGSV
          restart: always
          ports:
          - 8080:80
          networks:
          - web-db-net

          networks:
          web-db-net:


          Then change your connect line to refer to the db container by name (you would also need to specify port if not using the MySQL default, 3306):



          $con = mysqli_connect("db","mgsv_user","mgsvpass","mgsv");


          EDIT2: fixed docker-compose.yml so that networks actually works






          share|improve this answer






















          • I'm running docker-ce 18.03. How would it be possible to add the containers to the same Docker network and reference them by name?
            – user3523406
            Mar 23 at 4:16










          • I made an edit to show some docker networking
            – GracefulRestart
            Mar 23 at 18:19










          • Thank you but I got ERROR: In file './docker-compose.yml', network must be a mapping, not a string.. What did I miss?
            – user3523406
            Mar 24 at 8:43










          • as I mentioned, it was not tested. I just tested it and noticed my mistake. In the networks key, put a colon (:) at the end of the network name to make it a mapping. i have edited the code in my answer to reflect what I just tested.
            – GracefulRestart
            Mar 24 at 21:58










          • Thank you, but I got again Warning: mysqli_connect(): (HY000/2002): No such file or directory in /var/www/html/index.php on line 4 Failed to connect to MySQL: No such file or directory. Any idea?
            – user3523406
            Mar 24 at 23:59












          up vote
          1
          down vote










          up vote
          1
          down vote









          I believe the issue here is that localhost is not your database host. If that PHP script is running in the "www" docker container, localhost most likely does not have a listening MySQL server. IIRC, the "file not found" error from mysqli is due to not finding the MySQL socket on localhost. I also do not see that you are exposing any ports for the "db" image, so I am not sure how "www" is supposed to connect to a database running inside it.



          You would want to find what the address to the "db" docker container is, and what port it is listening on, then reference that in your mysqli_connect() function. An easier method, if you have a recent version of docker, would be to add your containers to the same Docker network and reference them by name.



          EDIT: Docker Networking



          You should read up on the networking feature in the official documentation as it is very useful. You can probably use the following docker-compose.yml (not tested):



          version: '3.1'

          services:
          db:
          image: mysql
          restart: always
          environment:
          - MYSQL_DATABASE=mgsv
          - MYSQL_USER=mgsv_user
          - MYSQL_PASSWORD=mgsvpass
          - MYSQL_ROOT_PASSWORD=mysql123
          volumes:
          - ./mysql:/docker-entrypoint-initdb.d
          networks:
          - web-db-net

          www:
          build: ./mGSV
          restart: always
          ports:
          - 8080:80
          networks:
          - web-db-net

          networks:
          web-db-net:


          Then change your connect line to refer to the db container by name (you would also need to specify port if not using the MySQL default, 3306):



          $con = mysqli_connect("db","mgsv_user","mgsvpass","mgsv");


          EDIT2: fixed docker-compose.yml so that networks actually works






          share|improve this answer














          I believe the issue here is that localhost is not your database host. If that PHP script is running in the "www" docker container, localhost most likely does not have a listening MySQL server. IIRC, the "file not found" error from mysqli is due to not finding the MySQL socket on localhost. I also do not see that you are exposing any ports for the "db" image, so I am not sure how "www" is supposed to connect to a database running inside it.



          You would want to find what the address to the "db" docker container is, and what port it is listening on, then reference that in your mysqli_connect() function. An easier method, if you have a recent version of docker, would be to add your containers to the same Docker network and reference them by name.



          EDIT: Docker Networking



          You should read up on the networking feature in the official documentation as it is very useful. You can probably use the following docker-compose.yml (not tested):



          version: '3.1'

          services:
          db:
          image: mysql
          restart: always
          environment:
          - MYSQL_DATABASE=mgsv
          - MYSQL_USER=mgsv_user
          - MYSQL_PASSWORD=mgsvpass
          - MYSQL_ROOT_PASSWORD=mysql123
          volumes:
          - ./mysql:/docker-entrypoint-initdb.d
          networks:
          - web-db-net

          www:
          build: ./mGSV
          restart: always
          ports:
          - 8080:80
          networks:
          - web-db-net

          networks:
          web-db-net:


          Then change your connect line to refer to the db container by name (you would also need to specify port if not using the MySQL default, 3306):



          $con = mysqli_connect("db","mgsv_user","mgsvpass","mgsv");


          EDIT2: fixed docker-compose.yml so that networks actually works







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 24 at 22:00

























          answered Mar 23 at 3:59









          GracefulRestart

          74917




          74917











          • I'm running docker-ce 18.03. How would it be possible to add the containers to the same Docker network and reference them by name?
            – user3523406
            Mar 23 at 4:16










          • I made an edit to show some docker networking
            – GracefulRestart
            Mar 23 at 18:19










          • Thank you but I got ERROR: In file './docker-compose.yml', network must be a mapping, not a string.. What did I miss?
            – user3523406
            Mar 24 at 8:43










          • as I mentioned, it was not tested. I just tested it and noticed my mistake. In the networks key, put a colon (:) at the end of the network name to make it a mapping. i have edited the code in my answer to reflect what I just tested.
            – GracefulRestart
            Mar 24 at 21:58










          • Thank you, but I got again Warning: mysqli_connect(): (HY000/2002): No such file or directory in /var/www/html/index.php on line 4 Failed to connect to MySQL: No such file or directory. Any idea?
            – user3523406
            Mar 24 at 23:59
















          • I'm running docker-ce 18.03. How would it be possible to add the containers to the same Docker network and reference them by name?
            – user3523406
            Mar 23 at 4:16










          • I made an edit to show some docker networking
            – GracefulRestart
            Mar 23 at 18:19










          • Thank you but I got ERROR: In file './docker-compose.yml', network must be a mapping, not a string.. What did I miss?
            – user3523406
            Mar 24 at 8:43










          • as I mentioned, it was not tested. I just tested it and noticed my mistake. In the networks key, put a colon (:) at the end of the network name to make it a mapping. i have edited the code in my answer to reflect what I just tested.
            – GracefulRestart
            Mar 24 at 21:58










          • Thank you, but I got again Warning: mysqli_connect(): (HY000/2002): No such file or directory in /var/www/html/index.php on line 4 Failed to connect to MySQL: No such file or directory. Any idea?
            – user3523406
            Mar 24 at 23:59















          I'm running docker-ce 18.03. How would it be possible to add the containers to the same Docker network and reference them by name?
          – user3523406
          Mar 23 at 4:16




          I'm running docker-ce 18.03. How would it be possible to add the containers to the same Docker network and reference them by name?
          – user3523406
          Mar 23 at 4:16












          I made an edit to show some docker networking
          – GracefulRestart
          Mar 23 at 18:19




          I made an edit to show some docker networking
          – GracefulRestart
          Mar 23 at 18:19












          Thank you but I got ERROR: In file './docker-compose.yml', network must be a mapping, not a string.. What did I miss?
          – user3523406
          Mar 24 at 8:43




          Thank you but I got ERROR: In file './docker-compose.yml', network must be a mapping, not a string.. What did I miss?
          – user3523406
          Mar 24 at 8:43












          as I mentioned, it was not tested. I just tested it and noticed my mistake. In the networks key, put a colon (:) at the end of the network name to make it a mapping. i have edited the code in my answer to reflect what I just tested.
          – GracefulRestart
          Mar 24 at 21:58




          as I mentioned, it was not tested. I just tested it and noticed my mistake. In the networks key, put a colon (:) at the end of the network name to make it a mapping. i have edited the code in my answer to reflect what I just tested.
          – GracefulRestart
          Mar 24 at 21:58












          Thank you, but I got again Warning: mysqli_connect(): (HY000/2002): No such file or directory in /var/www/html/index.php on line 4 Failed to connect to MySQL: No such file or directory. Any idea?
          – user3523406
          Mar 24 at 23:59




          Thank you, but I got again Warning: mysqli_connect(): (HY000/2002): No such file or directory in /var/www/html/index.php on line 4 Failed to connect to MySQL: No such file or directory. Any idea?
          – user3523406
          Mar 24 at 23:59












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f432976%2ffailed-to-connect-to-mysql-no-such-file-or-directory%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay