1

I am playing around to get a additional SQL Server container (as multi db playground setup for TYPO3) in ddev configuartion within docker-compose.override.yaml.

It works somehow and i can connect to the SQL Server from the host machine (to be honest with more luck than knowledge ;o).

What i absolutely don't know is how to connect the new mssql container to the web container that TYPO3 can access it. Absolutely no clue ;o( Any ideas?

UPDATE: I had a little progress with my problem see below. It was simpler than expected. Ddev is building a additional MsSql Server container and TYPO3 can access it with an additional DB config.

Don't know if this is a good practical way. Will investigate more if MsSql support in TYPO3 is useable.

docker-compose.override.yaml:

version: '3.6'

services:
  web:
    environment:
      - TYPO3_CONTEXT=Development/Ddev
    links:
      - mssql:mssql

  mssql:
    # https://hub.docker.com/_/microsoft-mssql-server
    image: "mcr.microsoft.com/mssql/server"
    volumes:
      - mssql-db-data:/var/opt/mssql/
    environment:
      SA_PASSWORD: "MyPassword001"
      ACCEPT_EULA: "Y"
    ports:
      - "1433:1433"
volumes:
  mssql-db-data:
    driver: local

DB Connections in LocalConfigurtion:

    'DB' => [
        'Connections' => [
            'Default' => [
                'charset'  => 'utf8',
                'dbname'   => 'db',
                'driver'   => 'mysqli',
                'host'     => 'db',
                'password' => 'db',
                'port'     => 3306,
                'user'     => 'db',            
            ],
            'MsSql' => [
                'charset' => 'UTF-8',
                'dbname' => 'master',
                'driver' => 'sqlsrv',
                'host' => 'mssql',
                'password' => 'MyPassword001',
                'port' => '1433',
                'user' => 'SA',
            ],
        ],
        'TableMapping' => [
            'sys_log' => 'MsSql',
        ],
    ],

Update 2:

Here is a little update see below.

docker-compose.mssql.yaml:

With this configuration i get in DDEV an mssql container.

version: '3.6'

services:
  web:
    links:
      - mssql:mssql

  mssql:
    # https://hub.docker.com/_/microsoft-mssql-server
    image: "mcr.microsoft.com/mssql/server"
    volumes:
      - mssql-db-data:/var/opt/mssql/
    environment:
      SA_PASSWORD: "MyPassword001"
      ACCEPT_EULA: "Y"
    ports:
      - "1433:1433"
volumes:
  mssql-db-data:
    driver: local

web-build/Dockerfile:

The web container needs additional packages. This Dockerfile works for me quite well. This link has a more advanced solution: How to install the SQL Server PHP drivers in DDEV-Local?

# https://ddev.readthedocs.io/en/stable/users/extend/customizing-images/#adding-extra-dockerfiles-for-webimage-and-dbimage
# https://stackoverflow.com/questions/58086933/how-to-install-the-sql-server-php-drivers-in-ddev-local#new-answer
ARG BASE_IMAGE
FROM $BASE_IMAGE

RUN curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
RUN curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list

RUN apt-get update
RUN apt-get --allow-downgrades -y install libssl1.1=1.1.1d-0+deb10u5
RUN apt-get -y update && yes | ACCEPT_EULA=Y apt-get -y install php7.4-dev php-pear unixodbc-dev htop
RUN ACCEPT_EULA=Y apt-get -y install msodbcsql17 mssql-tools
RUN sudo pecl channel-update pecl.php.net
RUN sudo pecl install sqlsrv
RUN sudo pecl install pdo_sqlsrv

RUN sudo printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/7.3/mods-available/sqlsrv.ini
RUN sudo printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/7.3/mods-available/pdo_sqlsrv.ini
RUN sudo phpenmod -v 7.3 -s cli sqlsrv pdo_sqlsrv
RUN sudo phpenmod -v 7.3 -s fpm sqlsrv pdo_sqlsrv
RUN sudo phpenmod -v 7.3 -s apache2 sqlsrv pdo_sqlsrv

RUN sudo printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/7.4/mods-available/sqlsrv.ini
RUN sudo printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/7.4/mods-available/pdo_sqlsrv.ini
RUN sudo phpenmod -v 7.4 -s cli sqlsrv pdo_sqlsrv
RUN sudo phpenmod -v 7.4 -s fpm sqlsrv pdo_sqlsrv
RUN sudo phpenmod -v 7.4 -s apache2 sqlsrv pdo_sqlsrv

RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile

  • I'm not sure if I understood your problem, u don't know how to access de mssql docker from the web docker? – Lucas Araújo Feb 17 '20 at 21:23
  • And you're sure you need an extra container, not just another database right? A database is super simple to create. – rfay Feb 19 '20 at 21:17

1 Answers1

0

Your configuration looks fine. This part links the mssql container to the web container:

services:
  web:
    links:
      - mssql:mssql

It should be accessible using the host mssql, as you've rightly set in your LocalConfiguration.php.

I wouldn't call the file docker-compose.override.yaml though. I'd call it docker-compose.mssql.yaml. That way you can more easily add multiple 'override' docker-compose files and easily copy them to other projects if needed. All docker-compose.*.yaml files will be loaded.

Rudy Gnodde
  • 4,286
  • 2
  • 12
  • 34