UNCLASSIFIED

README.md 5.21 KB
Newer Older
1
# SQL Server 2019 on Red Hat Enterprise Linux 8
balexand's avatar
balexand committed
2

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
# Prerequisites
- Minimum of 2 GB of disk space.
- Minimum of 2 GB of RAM.
- [System requirements for SQL Server on Linux.](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup?view=sql-server-ver15#system)

## 1. Run the container

To run the container image with Podman, you can use the following command from a bash shell

```
podman run \
-e "ACCEPT_EULA=Y" \
<provide the MSSQL_SA_PASSWORD environment variable definition here> \
-p 1433:1433 --name <provide the container name here (e.g. "sql1")> \
-d registry1.dsop.io/microsoft/sql-server:2019-CU8-rhel8
```

NOTE: besides the ```"ACCEPT_EULA=Y"``` environment variable, you must also provide to the container the ```"MSSQL_SA_PASSWORD"``` environment variable containing the password that you want to set for the system administrator (sa) account.

## 2. Change the SA password

The SA account is a system administrator on the SQL Server instance that gets created during setup. After creating your SQL Server container, the ```MSSQL_SA_PASSWORD``` environment variable you specified is discoverable by running ```echo $MSSQL_SA_PASSWORD``` in the container. For security purposes, change your SA password.

```
podman exec -it \
    <provide the container name here (e.g. "sql1")> \
    /opt/mssql-tools/bin/sqlcmd \
   -S localhost -U SA -P <provide the current password here surrounded by double quotes> \
   -Q 'ALTER LOGIN SA WITH PASSWORD=<provide the new password here surrounded by double quotes>'
```

## 3. Connect to SQL Server
### 3.1 Connect from inside the container

The following steps use the SQL Server command-line tool, sqlcmd, inside the container to connect to SQL Server.

```
podman exec -it <provide the container name here (e.g. "sql1")> "bash"
```
```
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P <provide the password here surrounded by double quotes>
```

### 3.2 Connect from outside the container

You can also connect to the SQL Server instance from any external Linux, Windows, or macOS tool that supports SQL connections.

The following steps use sqlcmd outside of your container to connect to SQL Server running in the container. These steps assume that you already have the SQL Server command-line tools installed outside of your container. The same principles apply when using other tools, but the process of connecting is unique to each tool.

1. Find the IP address for the machine that hosts your container. On Linux, use ```ifconfig``` or ```ip addr```. On Windows, use ```ipconfig```.

2. For this example, install the sqlcmd tool on your client machine. For more information, see [Install sqlcmd on Windows](https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility?view=sql-server-ver15) or [Install sqlcmd on Linux](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-tools?view=sql-server-ver15).

3. Run sqlcmd specifying the IP address and the port mapped to port 1433 in your container. In this example, that is the same port, 1433, on the host machine. If you specified a different mapped port on the host machine, you would use it here.

    ```
    sqlcmd -S <ip_address>,1433 -U SA -P <provide the new password here surrounded by double quotes>
    ```

4. Run Transact-SQL commands. When finished, type ```QUIT```.

Other common tools to connect to SQL Server include:

- [Visual Studio Code](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-develop-use-vscode?view=sql-server-ver15)
- [SQL Server Management Studio (SSMS) on Windows](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-manage-ssms?view=sql-server-ver15)
- [Azure Data Studio](https://docs.microsoft.com/en-us/sql/azure-data-studio/what-is?view=sql-server-ver15)
- [mssql-cli (Preview)](https://github.com/dbcli/mssql-cli/blob/master/doc/usage_guide.md)
- [PowerShell Core](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-manage-powershell-core?view=sql-server-ver15)

## 4. Container Healthcheck

The health check of the container relies on the SQL Server Extended Events technology. What the logic of the health check does is look for updates in system health files of an Extended Events session that is created by default when the container is executed. Given the latter, this Extended Events session must not be stopped and the location of the system health files must not be changed. The health check does, however, check for those system health files in two possible locations:

- The default location at ```/var/opt/mssql/log```.
- The parent directory of the file whose path can be configured by the ```MSSQL_ERROR_LOG_FILE``` environment variable. By default, system health files are always placed next to SQL Server error log files.

See [SQL Docs - Extended Events Overview](https://docs.microsoft.com/en-us/sql/relational-databases/extended-events/extended-events?view=sql-server-ver15) and [SQL Docs - Configure SQL Server settings with environment variables on Linux](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-environment-variables?view=sql-server-ver15).

<br>

See the full documentation of SQL Server containers on [SQL Docs - Quickstart: Run SQL Server container images with Docker](https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-ver15&pivots=cs1-bash).