Skip to content

Working with SQL Server Containers

This article covers the process of setting up a Webslice Container running the Microsoft SQL Server service image, then accessing the database.

Creating a SQL Server Container

This is the same as creating a Container of any other sort. You’ll find Microsoft SQL Server under Service images. When you create the container, you’ll also need to:

  • Create an SSH user. This user needs to be unique to this container, i.e. not associated with any other containers.
  • Provide a system admin password. (You might want to read Microsoft’s SQL Server password policy.)

Connecting to SQL Server

There are three ways to connect to SQL Server:

  • Via the sqlcmd utility tool.
  • By using a Web Container - we recommend one running the .NET Core + SDK web image.
  • Via an external application.

Connecting via the SQLCMD tool

  1. SSH into the container.

  2. Locate the sqlcmd tool in /opt/mssql-tools/bin/sqlcmd

  3. Use this command, with your container name and system admin password:

    /opt/mssql-tools/bin/sqlcmd -S [container name] -U SA -P <YourMSSQLSAPassword>

This will allow you to modify your SQL Server database with Transact-SQL queries, which you can read about in documentation from Microsoft.

Connecting via a Web Container

You can connect to your SQL Server container via another container. We recommend using a .NET Core + SDK Web Application to do this. If your Web Container is on a different server, you’ll need to publish the relevant port.

In your web application, you will need to use the internal container name as the host. The tip above tells you how to find this name.

Connecting via an external application

If you have published the 1433 port for SQL Server, you will be able to connect to the SQL Server instance via the SQL Server hostname and published port.

Backups

Like all Webslice Containers, your SQL Server container will by automatically backed up once a day. You can also take manual backups whevever you need. For more, see Backing Up Containers.

You can find backups in the directory /container/backup/containers. For more, see Restoring Backups and Microsoft’s guide: Restore a database backup under the simple recovery model (Transact-SQL).

If you need to restore the master database for SQL Server, you will need to contact the Support Team.

SQL Server requires a copy of the backup to exist on disk, so you’ll need to copy the relevant backup files onto your container to initiate the backup.