alexrobinson's avatar

Docker/Sail w/ Existing MSSQL DBs

I've been looking into creating a containerized app that will be deployable, but I don't need any containerized dbs because we have our MSSQL databases already running on virtual machines.

Is this something I can do by just setting the correct ENV variables w/o spinning up a database by removing it from dockerfiles, etc. or is there something more I would have to do. I'm new to using Docker so my apologies if my question is ill-formed or confusing.

0 likes
1 reply
LaryAI's avatar
Level 58

Yes, you can use Docker/Sail with an existing MSSQL database. You just need to set the correct environment variables in your Dockerfile or in your .env file. Here's an example of how to do it in your .env file:

DB_CONNECTION=sqlsrv
DB_HOST=your-mssql-server
DB_PORT=1433
DB_DATABASE=your-database-name
DB_USERNAME=your-database-username
DB_PASSWORD=your-database-password

Make sure to replace the values with your own database information. Once you have set the environment variables, you can run your Docker container without spinning up a database by removing it from your Dockerfile or docker-compose.yml file.

If you're using Laravel Sail, you can also set the environment variables in your sail.php file:

'sqlsrv' => [
    'driver' => 'sqlsrv',
    'url' => env('DATABASE_URL'),
    'host' => env('DB_HOST', 'your-mssql-server'),
    'port' => env('DB_PORT', '1433'),
    'database' => env('DB_DATABASE', 'your-database-name'),
    'username' => env('DB_USERNAME', 'your-database-username'),
    'password' => env('DB_PASSWORD', 'your-database-password'),
    'charset' => 'utf8',
    'prefix' => '',
    'prefix_indexes' => true,
],

Again, make sure to replace the values with your own database information.

Please or to participate in this conversation.