Prerequisite: VirtualBox
. Grab your copy here:
https://www.virtualbox.org/wiki/Downloads
Official docker app is not running on the older Macs but we still can make
MSSQL run on those machines and that's fucking awesome.
Firs of all we have to install boot2docker
$ brew install boot2docker
After a successful installation you'll see something like this:
Generating public/private rsa key pair.
Your identification has been saved in /Users/<your account name>/.ssh/id_boot2docker.
Your public key has been saved in /Users/<your account name>/.ssh/id_boot2docker.pub.
The key fingerprint is:
SHA256:somefingeprint <your account name>@home
To connect the Docker client to the Docker daemon, please set:
export DOCKER_HOST=tcp://<your-docker-IP>:2376
export DOCKER_CERT_PATH=/Users/<your account name>/.boot2docker/certs/boot2docker-vm
export DOCKER_TLS_VERIFY=1
Or run: `eval "$(boot2docker shellinit)"`
Run eval "$(boot2docker shellinit)"
and it will add your docker settings to your ~/.bash_profile
MSSQL needs at least 4 gigs of RAM. You have to configure your docker accroding to it:
$ boot2docker init -m 4096
Ok, you should be ready know to run MSSQL
$ docker run --name mssql -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -d microsoft/mssql-server-linux
By providing a --name mssql
option, we're giving our container a name and can interact with it later by using this name mssql
If you want to connect to MSSQL from the console, there's an npm
package for that:
npm install -g sql-cli
Once installed you can connect to your MSSQL instance by running:
$ mssql -s <your-docker-IP> -u SA -p 'yourStrong(!)Password'
If you want to make your life with docker
a little bit easier you can put this piece of code into your ~/.bash_profile
Change the IP of your docker accordingly.
# mssql functions
function ms() {
if [ "$@" = start ]
then
echo "don't forget to 'boot2docker start' first"
msstart
elif [ "$@" = connect ]
then
msconnect
elif [ "$@" = stop ]
then
docker stop mssql && docker rm mssql
else
echo "provide an option either 'start', 'connect' or 'stop'"
fi
}
# start mssql
function msstart() {
docker run --name mssql -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -d microsoft/mssql-server-linux
}
export -f msstart
#connect to mssql
function msconnect() {
mssql -s <your-docker-IP> -u SA -p 'yourStrong(!)Password'
}
export -f msconnect
You'll be able to start, stop and connect to MSSQL by running
$ ms start
$ ms connect
$ ms stop
Once you start MSSQL with $ ms start
docker will give you an identifier for your container.
To see the logs, just run
$ docker logs -f <identifier>
To see what containers are runnig use
$ docker ps
If you cannot remove your container by using the name mssql
, try to remove it by using the container identifier
$ docker rm <identifier>
You'll find two sql scripts to create a sample database.
Connect to MSSQL by running ms connect
(you have to start MSSQL first if it's not running) and run from the mssql
console
> .run path/to/sample-model.sql
> .run path/to/sample-data.sql
In case you're experiencing problems with docker
looking for certifcates in
the wrong place, try to change following line in your ~/.bash_profile
from
export DOCKER_CERT_PATH=/Users/<your username>/.boot2docker/certs/boot2docker-vm
to
export DOCKER_CERT_PATH=/Users/<your username>/.docker/machine/machines/default