Docker Compose Sql DB image connection error












-1














I have a docker-compose.yml file and I want to create three containers to run my node app: a client, a server, a db container with some data.



I have troubles to create the db container and connect it to the server container, I'm using sequelize to connect with db, but on docker-compose up command I have connection error on server app startup:




server_1 | Unable to connect to SQL database: webgrit_superactivation { SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306




this is my docker-compose file:



version: "3"

services:
# client
client:
image: "ngapp"
build: "client/dist/."
ports:
- "4200:80"
# Server
server:
image: "exapp"
build: "server/."
ports:
- "3000:3000"
links:
- db
# MySQL
db:
image: mysql:5.7
command: mysqld --user=root
volumes:
- ./mysql-dump:/docker-entrypoint-initdb.d
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: myuser
MYSQL_PASSWORD: mypass
MYSQL_DATABASE: mydbname


in the mysql image I use a data.sql dump file to init my db, but something is wrong



this is my server container dbconfig.js file that I use to connect with mysql db:



CONFIG.db_name = process.env.DB_NAME_DEV || "mydbname";
CONFIG.db_user = process.env.DB_USER_DEV || "myuser";
CONFIG.db_password = process.env.DB_PASSWORD_DEV || "mypass";
CONFIG.db_dialect = process.env.DB_DIALECT_DEV || "mysql";
CONFIG.db_host = process.env.DB_HOST_DEV || "localhost";
CONFIG.db_port = process.env.DB_PORT_DEV || "3306";


and this is the start of my data.sql dump file:



SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";

CREATE DATABASE IF NOT EXISTS `mydbname` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `mydbname`;

CREATE TABLE `users` (
...


Edit: here you can find an error log: https://github.com/ufollettu/SEANSA/blob/master/docker%20error%20log.log



I'm pretty new to docker, how can I solve this problem?
thanks for help










share|improve this question





























    -1














    I have a docker-compose.yml file and I want to create three containers to run my node app: a client, a server, a db container with some data.



    I have troubles to create the db container and connect it to the server container, I'm using sequelize to connect with db, but on docker-compose up command I have connection error on server app startup:




    server_1 | Unable to connect to SQL database: webgrit_superactivation { SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306




    this is my docker-compose file:



    version: "3"

    services:
    # client
    client:
    image: "ngapp"
    build: "client/dist/."
    ports:
    - "4200:80"
    # Server
    server:
    image: "exapp"
    build: "server/."
    ports:
    - "3000:3000"
    links:
    - db
    # MySQL
    db:
    image: mysql:5.7
    command: mysqld --user=root
    volumes:
    - ./mysql-dump:/docker-entrypoint-initdb.d
    environment:
    MYSQL_ROOT_PASSWORD: root
    MYSQL_USER: myuser
    MYSQL_PASSWORD: mypass
    MYSQL_DATABASE: mydbname


    in the mysql image I use a data.sql dump file to init my db, but something is wrong



    this is my server container dbconfig.js file that I use to connect with mysql db:



    CONFIG.db_name = process.env.DB_NAME_DEV || "mydbname";
    CONFIG.db_user = process.env.DB_USER_DEV || "myuser";
    CONFIG.db_password = process.env.DB_PASSWORD_DEV || "mypass";
    CONFIG.db_dialect = process.env.DB_DIALECT_DEV || "mysql";
    CONFIG.db_host = process.env.DB_HOST_DEV || "localhost";
    CONFIG.db_port = process.env.DB_PORT_DEV || "3306";


    and this is the start of my data.sql dump file:



    SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
    SET AUTOCOMMIT = 0;
    START TRANSACTION;
    SET time_zone = "+00:00";

    CREATE DATABASE IF NOT EXISTS `mydbname` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
    USE `mydbname`;

    CREATE TABLE `users` (
    ...


    Edit: here you can find an error log: https://github.com/ufollettu/SEANSA/blob/master/docker%20error%20log.log



    I'm pretty new to docker, how can I solve this problem?
    thanks for help










    share|improve this question



























      -1












      -1








      -1







      I have a docker-compose.yml file and I want to create three containers to run my node app: a client, a server, a db container with some data.



      I have troubles to create the db container and connect it to the server container, I'm using sequelize to connect with db, but on docker-compose up command I have connection error on server app startup:




      server_1 | Unable to connect to SQL database: webgrit_superactivation { SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306




      this is my docker-compose file:



      version: "3"

      services:
      # client
      client:
      image: "ngapp"
      build: "client/dist/."
      ports:
      - "4200:80"
      # Server
      server:
      image: "exapp"
      build: "server/."
      ports:
      - "3000:3000"
      links:
      - db
      # MySQL
      db:
      image: mysql:5.7
      command: mysqld --user=root
      volumes:
      - ./mysql-dump:/docker-entrypoint-initdb.d
      environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_USER: myuser
      MYSQL_PASSWORD: mypass
      MYSQL_DATABASE: mydbname


      in the mysql image I use a data.sql dump file to init my db, but something is wrong



      this is my server container dbconfig.js file that I use to connect with mysql db:



      CONFIG.db_name = process.env.DB_NAME_DEV || "mydbname";
      CONFIG.db_user = process.env.DB_USER_DEV || "myuser";
      CONFIG.db_password = process.env.DB_PASSWORD_DEV || "mypass";
      CONFIG.db_dialect = process.env.DB_DIALECT_DEV || "mysql";
      CONFIG.db_host = process.env.DB_HOST_DEV || "localhost";
      CONFIG.db_port = process.env.DB_PORT_DEV || "3306";


      and this is the start of my data.sql dump file:



      SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
      SET AUTOCOMMIT = 0;
      START TRANSACTION;
      SET time_zone = "+00:00";

      CREATE DATABASE IF NOT EXISTS `mydbname` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
      USE `mydbname`;

      CREATE TABLE `users` (
      ...


      Edit: here you can find an error log: https://github.com/ufollettu/SEANSA/blob/master/docker%20error%20log.log



      I'm pretty new to docker, how can I solve this problem?
      thanks for help










      share|improve this question















      I have a docker-compose.yml file and I want to create three containers to run my node app: a client, a server, a db container with some data.



      I have troubles to create the db container and connect it to the server container, I'm using sequelize to connect with db, but on docker-compose up command I have connection error on server app startup:




      server_1 | Unable to connect to SQL database: webgrit_superactivation { SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306




      this is my docker-compose file:



      version: "3"

      services:
      # client
      client:
      image: "ngapp"
      build: "client/dist/."
      ports:
      - "4200:80"
      # Server
      server:
      image: "exapp"
      build: "server/."
      ports:
      - "3000:3000"
      links:
      - db
      # MySQL
      db:
      image: mysql:5.7
      command: mysqld --user=root
      volumes:
      - ./mysql-dump:/docker-entrypoint-initdb.d
      environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_USER: myuser
      MYSQL_PASSWORD: mypass
      MYSQL_DATABASE: mydbname


      in the mysql image I use a data.sql dump file to init my db, but something is wrong



      this is my server container dbconfig.js file that I use to connect with mysql db:



      CONFIG.db_name = process.env.DB_NAME_DEV || "mydbname";
      CONFIG.db_user = process.env.DB_USER_DEV || "myuser";
      CONFIG.db_password = process.env.DB_PASSWORD_DEV || "mypass";
      CONFIG.db_dialect = process.env.DB_DIALECT_DEV || "mysql";
      CONFIG.db_host = process.env.DB_HOST_DEV || "localhost";
      CONFIG.db_port = process.env.DB_PORT_DEV || "3306";


      and this is the start of my data.sql dump file:



      SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
      SET AUTOCOMMIT = 0;
      START TRANSACTION;
      SET time_zone = "+00:00";

      CREATE DATABASE IF NOT EXISTS `mydbname` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
      USE `mydbname`;

      CREATE TABLE `users` (
      ...


      Edit: here you can find an error log: https://github.com/ufollettu/SEANSA/blob/master/docker%20error%20log.log



      I'm pretty new to docker, how can I solve this problem?
      thanks for help







      mysql node.js docker docker-compose sequelize.js






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 '18 at 10:17

























      asked Nov 12 '18 at 9:58









      ufollettu

      100110




      100110
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Change host to DB service name i.e db -



          CONFIG.db_host = process.env.DB_HOST_DEV || "db";






          share|improve this answer





















          • Sorry, but doesn't works. It seems there's an error in the db initialization. I added a error log in my question.
            – ufollettu
            Nov 12 '18 at 10:18











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          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',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53259723%2fdocker-compose-sql-db-image-connection-error%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Change host to DB service name i.e db -



          CONFIG.db_host = process.env.DB_HOST_DEV || "db";






          share|improve this answer





















          • Sorry, but doesn't works. It seems there's an error in the db initialization. I added a error log in my question.
            – ufollettu
            Nov 12 '18 at 10:18
















          1














          Change host to DB service name i.e db -



          CONFIG.db_host = process.env.DB_HOST_DEV || "db";






          share|improve this answer





















          • Sorry, but doesn't works. It seems there's an error in the db initialization. I added a error log in my question.
            – ufollettu
            Nov 12 '18 at 10:18














          1












          1








          1






          Change host to DB service name i.e db -



          CONFIG.db_host = process.env.DB_HOST_DEV || "db";






          share|improve this answer












          Change host to DB service name i.e db -



          CONFIG.db_host = process.env.DB_HOST_DEV || "db";







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 12 '18 at 10:07









          vivekyad4v

          3,32321426




          3,32321426












          • Sorry, but doesn't works. It seems there's an error in the db initialization. I added a error log in my question.
            – ufollettu
            Nov 12 '18 at 10:18


















          • Sorry, but doesn't works. It seems there's an error in the db initialization. I added a error log in my question.
            – ufollettu
            Nov 12 '18 at 10:18
















          Sorry, but doesn't works. It seems there's an error in the db initialization. I added a error log in my question.
          – ufollettu
          Nov 12 '18 at 10:18




          Sorry, but doesn't works. It seems there's an error in the db initialization. I added a error log in my question.
          – ufollettu
          Nov 12 '18 at 10:18


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53259723%2fdocker-compose-sql-db-image-connection-error%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Hercules Kyvelos

          Tes-Khemsky District

          Tangent Lines Diagram Along Smooth Curve