Ubuntu - Accessing SQL Server on Docker Container

Thiago S. Adriano
dockerbr
Published in
1 min readJun 11, 2017

Today we’ll see how access a database in Docker container with sqlcmd in Ubuntu.

In our last history we saw how create a container SQL Server, today we’ll create a database and connect.

The first step is install mssql-tools, to do this we need:

Import the public repository GPG keys.

curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

Register the Microsoft Ubuntu repository.

curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

Update the sources list and run the installation command with the unixODBC developer package.

sudo apt-get update  
sudo apt-get install mssql-tools unixodbc-dev

Now to connect the SQL Server created in our last history we need to execute this command below:

sqlcmd -S localhost,11433 -U SA -P 'SqlOnDocker';

Finally we can execute the command below the show all databases:

SELECT Name from sys.Databases;

And to execute this command:

go

Now we can see the result below:

--

--