title: Docker NodeJS with MySQL connect ECONNREFUSED 127.0.0.1:8000
body: <p>I have 2 container which is mysql and nodejs. However, the connection between my nodejs and mysql doesnt seem to be connected. The error is </p>
  
  <pre><code>connect ECONNREFUSED 127.0.0.1:8000 
  </code></pre>
  
  <p>My server.js file </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>//Connection with database
  var mysql = require('mysql');
  var con = mysql.createConnection({
    host: "localhost",
    port: "8000",
    user: "root",
    password: "root",
    database: "justcall"
  });
  
    con.connect(function(err){
            if(err){
              console.log('Database connection error: ' + err.message);
            }else{
              console.log('Database connection successful');
            }
          });</code></pre>
  </div>
  </div>
  </p>
  
  <p>Dockerfile for my nodejs</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>FROM node:12
  RUN useradd -ms /bin/bash admin
  WORKDIR /app
  COPY . /app
  RUN chown -R admin:admin /app
  RUN chmod 755 /app
  USER admin
  CMD npm start
  EXPOSE 4443</code></pre>
  </div>
  </div>
  
  I build the image using</p>
  
  <pre><code>docker build -t nodejs:signalingserver2
  </code></pre>
  
  <p>I run the container using</p>
  
  <pre><code>docker run -p 4443:4443 nodejs:signalingserver2
  </code></pre>
  
  <p>My mysql docker-compose is</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>version: '3'
  services:
  
    mysql:
          image: mysql:8.0
          container_name: mysql-server-80
  #        command: --default-authentication-plugin=msql_native_password
  #       working dir: /application
          volumes:
            - .:/application
          restart: always
          ports:
            - '3306:3306'
          expose:
            - '3306'
          environment:
            - MYSQL_ROOT_PASSWORD=root
            - MYSQL_DATABASE=mydb
            - MYSQL_USER=root
            - MYSQL_PASSWORD=root
    phpmyadmin:
      depends_on:
        - mysql
      image: phpmyadmin/phpmyadmin
      container_name: phpmyadmin
      restart: always
      ports:
        - "8080:80"
      links:
        - mysql
      environment:
        PMA_HOSTS: mysql
  
    php:
      container_name: php
      image: php:php_img
      build:
        context: ./
      volumes:
        - /root/app/xampp/justcall:/var/www/html
      ports:
        - 8000:80
      depends_on:
        - mysql
      restart: always</code></pre>
  </div>
  </div>
  </p>
  
  <p>The problem is everytime i run my nodejs server, it has an error which is ECONNREFUSED</p>