devilbox icon indicating copy to clipboard operation
devilbox copied to clipboard

[Feature]: MSSQL

Open Maik1511 opened this issue 3 years ago • 1 comments

What is your idea or feature suggestion?

Wie wäre es mit im SQL Stack MSSQL Server 2022 mit aufzunehmen?

Benefits

No response

Where can we find information about this?

https://hub.docker.com/_/microsoft-mssql-server

Are you willing to provide a PR to address this?

No response

Maik1511 avatar Oct 09 '22 06:10 Maik1511

I've had a use case for a specific website that used this in the past, haven't had to use it in a long time so not entirely sure if this still works perfectly. I cannot find the original article anymore that helped me find the solution (especially the script for the PHP containers) but my changes in the docker-compose.override.yml file are still on my machine, so if it helps, here it is. In my case I needed 2017, but you can of course use a different version.

docker-compose.override.yml

Add the image to your services and make sure your ipv4_address doesn't conflict with another service you might have added. If you want persistent data (so not losing your databases after restarts) you should also add the volume that i added in the bottom.

services:
  # -----------------------------------------------------------------------------------------------
  # Microsoft SQL server
  # -----------------------------------------------------------------------------------------------
  mssql:
    image: mcr.microsoft.com/mssql/server:2017-latest
    hostname: mssql
    environment:
      - ACCEPT_EULA=${MSSQL_ACCEPT_EULA:-yes}
      - SA_PASSWORD=${MSSQL_SA_PASSWORD:-default_password}
      - MSSQL_PID=Express
    ports:
      - "${LOCAL_LISTEN_ADDR}${HOST_PORT_MSSQL:-1433}:1433"
    networks:
      app_net:
        ipv4_address: 172.16.238.200
    volumes:
      # Add this volume to persist data
      - devilbox-mssql-2017:/var/opt/mssql:rw${MOUNT_OPTIONS}
    depends_on:
      - bind
      - php
      - httpd

volumes:
  # ------------------------------------------------------------
  # MSSQL
  # ------------------------------------------------------------
  devilbox-mssql-2017:

.env

In your .env file you can add the following keys and values. For picking a password there's some demands that MSSQL might make (minimum size, numbers and letters etc.)

################################################################################
###
### Mssql
###
################################################################################
HOST_PORT_MSSQL=1433
MSSQL_ACCEPT_EULA=yes
MSSQL_SA_PASSWORD=some_password_you_should_change

By default, the PHP modules for MSSQL are disabled in the Devilbox ENV file. In your ENV file, go to the PHP_MODULES_DISABLE value and remove pdo_sqlsrv and sqlsrv

autostart/ms-odbc.sh

In the autostart folder you can add a script to install MS ODBC on the start of every PHP container.

#
# This script will automatically install the Microsoft ODBC driver for MsSQL
# support for PHP during startup.
#
# In order for it to work, you must read and accept their License/EULA:
# https://odbceula.blob.core.windows.net/eula17/LICENSE172.TXT
#


# ------------------------------------------------------------------------------------------------
# EDIT THE VARIABLE BELOW TO ACCEPT THE EULA (If you agree to their terms)
# ------------------------------------------------------------------------------------------------

###
### Set this to "Y" (capital 'Y') if you accept the EULA.
###
ACCEPT_EULA=Y



# ------------------------------------------------------------------------------------------------
# DO NOT EDIT BELOW THIS LINE
# ------------------------------------------------------------------------------------------------

###
### Where to retrieve the deb package
###
MSODBC_URL="https://packages.microsoft.com/debian/8/prod/pool/main/m/msodbcsql17/"


###
### Pre-flight check
###
if [ "${ACCEPT_EULA}" != "Y" ]; then
     echo "MS ODBC EULA not accepted. Aborting installation."
     exit 0
fi


###
### EULA accepted, so we can proceed
###

# Extract latest *.deb packate
MSODBC_DEB="$( curl -k -sS "${MSODBC_URL}" | grep -Eo 'msodbcsql[-._0-9]+?_amd64\.deb' | tail -1 )"

# Download to temporary location
curl -k -sS "${MSODBC_URL}${MSODBC_DEB}" > "/tmp/${MSODBC_DEB}"

# Install
ACCEPT_EULA="${ACCEPT_EULA}" dpkg -i "/tmp/${MSODBC_DEB}"

# Remove artifacts
rm -f "/tmp/${MSODBC_DEB}"

Start the service

This runs the SQL server container and adds it to your devilbox network.

docker-compose up -d srv-mssql

Hopefully this helps you find what you need

Lenitr avatar May 11 '23 12:05 Lenitr