title: Use docker-compose for NodeJS and SQL Server
body: <p>I have the <code>docker-compose.yml</code> below:</p>
  <pre><code>version: &quot;3.7&quot;
  services:
     sql-server-db:
       container_name: sql-server-db
       image: mcr.microsoft.com/mssql/server:2019-latest
       ports:
         - &quot;1433:1433&quot;
       environment:
         SA_PASSWORD: &quot;Thieu@098551298&quot;
         ACCEPT_EULA: &quot;Y&quot;
  </code></pre>
  <p>I will run command:</p>
  <pre><code>docker-compose up -d
  </code></pre>
  <p>I used 2 command to go my database</p>
  <pre><code>$ docker exec -it sql-server-db &quot;bash&quot;
  $ /opt/mssql-tools/bin/sqlcmd -s localhost -U SA -P Thieu@098551298
  
  1&gt; select name from sys.databases
  2&gt; go
  name
  --------------------------------------------------------------------------------------------------------------------------------
  master
  tempdb
  model
  msdb
  </code></pre>
  <p>Then I will create and insert data:</p>
  <pre><code>1&gt; create database blog
  2&gt; go
  1&gt; use blog
  2&gt; go
  Changed database context to 'blog'.
  1&gt; create table post (id int,title nvarchar(100),content nvarchar(100))
  2&gt; go
  1&gt; insert into post values(1,&quot;How to learn docker&quot;,&quot; qwe qwje qwb ejqwbe bqwe bqwe bqwje jkqwn e&quot;)
  2&gt; go
  
  (1 rows affected)
  1&gt; select *from post
  2&gt; go
  id         ltitle                                                                                               lcontent                   
  
  -----------l----------------------------------------------------------------------------------------------------l----------------------------------------------------------------------------------------------------
            1lHow to learn docker                                                                                 l qwe qwje qwb ejqwbe bqwe bqwe bqwje jkqwn e
  
  (1 rows affected)
  1&gt;
  </code></pre>
  <p>When I have the database above I write:</p>
  <pre><code>var sql = require('mssql')
  
  var config = {
      user: 'sa',
      password: 'Thieu@098551298',
      server: 'localhost',
      database: &quot;blog&quot;,
      options: {
          enableArithAbort: true,
          trustServerCertificate: true
      }
  }
  
  function ExecuteSQL(query) {
      return new Promise((resolve, reject) =&gt; {
          sql.connect(config, (err, db) =&gt; {
              if (err) reject(err);
              var request = new sql.Request();
              request.query(query, (err, db) =&gt; {
                  if (err) reject(err);
                  resolve(db);
              });
          })
      })
  }
  async function z(){
      var z = await ExecuteSQL(&quot;select *from post&quot;)
      console.log(z.recordsets)
  }
  z()
  </code></pre>
  <p>It will throw an error:</p>
  <blockquote>
  <p>ConnectionError: Login failed for user 'sa'.</p>
  </blockquote>
  <p>Purpose: I want to display the data I just added, but it seems to connect to SQL Server on my machine so is there any way I can connect to Docker SQL Server. Thank you.</p>