- PHP 8.2-fpm
- Laravel 11
- Laravel 11 - must have ODBC Driver 17 for SQL Server
- MS SQL Server
build the docker images
docker compose build
or
docker compose build --no-cache
important files to review and change:
- for the overall docker configuration
- for variables see .env files on .env
- see how the MSSQL support is created docker/app.dockerfile
- see how nginx is created to serve laravel docker/web.dockerfile
- see how nginx is configured docker/vhost.conf
- remember : app:9000 is pointing to the laravel php container
place you laravel app on app folder if needed (for example if you are using Vite) go to app folder and run
docker exec -it app sh
#cd /var/www/app/
# npm run dev
or
npm run dev -- --host
simply run
docker compose up -d
visit your web app at laravel.docker.localhost do not forget to configure your laravel app .env file as shown in our sample file with
DB_CONNECTION=sqlsrv
DB_HOST=sqlsrv
# DB_PORT=1433
DB_DATABASE=ekne
DB_USERNAME=sa
DB_PASSWORD=yourStrong!pass
DB_TRUST_SERVER_CERTIFICATE=true
Also visit adminner as sql client to import your database
System: MS SQL (beta)
Server: sqlsrv
Username: sa
Pass: ${DB_PASSWORD} see .env file
db: databases
we MSSQL Adminer
on http://laravel.docker.localhost:8081/
using these credentials
server: MS SQL (beta)
mssql: sqlsrv
username: sa
password: yourStrong!pass
find databases on adminer
SELECT name, database_id, create_date FROM sys.databases; GO
on your laravel app add this connection string to MSSQL
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'sqlsrv'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'test'),
'username' => env('DB_USERNAME', 'sa'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'options' => [
'TrustServerCertificate' => 'Yes',
'trust_server_certificate'=>'yes'
],
'trust_server_certificate'=>'yes',
'TrustServerCertificate' => 'Yes',
],
Go ahead and read
but speed instructions are here :
curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
sudo apt-get update && sudo apt-get install mssql-tools18
now you can import your db
source .env
docker exec -it sqlsrv sh
docker exec -it sqlsrv /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P yourStrong!pass -C -i /var/www/test_export.sql
or from iside of the container
docker exec -it sqlsrv sh
/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P '${DB_PASSWORD}' -C
Getting :
SQLSTATE[08001]: [Microsoft][ODBC Driver 17 for SQL Server]SSL Provider: [OpenSSL library could not be loaded, make sure OpenSSL 1.0 or 1.1 is installed] (Connection: sqlsrv, SQL: select top 1 * from [User] where [UserID] = agelos)
this change (to update to the latest deb) seems to resolve the issue RUN curl -o msodbcsql17_amd64.deb https://packages.microsoft.com/debian/9/prod/pool/main/m/msodbcsql17/msodbcsql17_17.10.6.1-1_amd64.deb RUN ACCEPT_EULA=Y dpkg -i msodbcsql17_amd64.deb