Unable to connect to MSSQL Database

Hello, I am unable to connect to a MSSQL Express DB which is locally hosted.
I run the Linux Octopus docker container with
docker run --privileged --interactive --detach --name OctopusDeploy --publish 1322:8080 --env ACCEPT_EULA='Y' --env DB_CONNECTION_STRING='Server=localhost,1433;Database=octoDB;User=sa;Password=super_secret' octopusdeploy/octopusdeploy:2020.5.2

I receive the following in the container logs:

======== Writing Configuration File =======
time="2020-12-22T14:24:14.486210700Z" level=info msg="Starting up"
time="2020-12-22T14:24:14.487448600Z" level=info msg="libcontainerd: started new containerd process" pid=28
time="2020-12-22T14:24:14.487491500Z" level=info msg="parsed scheme: \"unix\"" module=grpc
time="2020-12-22T14:24:14.487523300Z" level=info msg="scheme \"unix\" not registered, fallback to default scheme" module=grpc
time="2020-12-22T14:24:14.487624800Z" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:///var/run/docker/containerd/containerd.sock  <nil> 0 <nil>}] <nil> <nil>}" module=grpc
time="2020-12-22T14:24:14.487652300Z" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
time="2020-12-22T14:24:14.506230500Z" level=info msg="starting containerd" revision=269548fa27e0089a8b8278fc4fc781d7f65a939b version=1.4.3
time="2020-12-22T14:24:14.534427600Z" level=info msg="loading plugin \"io.containerd.content.v1.content\"..." type=io.containerd.content.v1
time="2020-12-22T14:24:14.534605300Z" level=info msg="loading plugin \"io.containerd.snapshotter.v1.aufs\"..." type=io.containerd.snapshotter.v1
time="2020-12-22T14:24:14.534824400Z" level=info msg="skip loading plugin \"io.containerd.snapshotter.v1.aufs\"..." error="aufs is not supported (modprobe aufs failed: exec: \"modprobe\": executable file not found in $PATH \"\"): skip plugin" type=io.containerd.snapshotter.v1
time="2020-12-22T14:24:14.534850600Z" level=info msg="loading plugin \"io.containerd.snapshotter.v1.btrfs\"..." type=io.containerd.snapshotter.v1
time="2020-12-22T14:24:14.535085800Z" level=info msg="skip loading plugin \"io.containerd.snapshotter.v1.btrfs\"..." error="path /var/lib/docker/containerd/daemon/io.containerd.snapshotter.v1.btrfs (ext4) must be a btrfs filesystem to be used with the btrfs snapshotter: skip plugin" type=io.containerd.snapshotter.v1
time="2020-12-22T14:24:14.535106500Z" level=info msg="loading plugin \"io.containerd.snapshotter.v1.devmapper\"..." type=io.containerd.snapshotter.v1
time="2020-12-22T14:24:14.535120500Z" level=warning msg="failed to load plugin io.containerd.snapshotter.v1.devmapper" error="devmapper not configured"
time="2020-12-22T14:24:14.535128600Z" level=info msg="loading plugin \"io.containerd.snapshotter.v1.native\"..." type=io.containerd.snapshotter.v1
time="2020-12-22T14:24:14.535199700Z" level=info msg="loading plugin \"io.containerd.snapshotter.v1.overlayfs\"..." type=io.containerd.snapshotter.v1
time="2020-12-22T14:24:14.535373200Z" level=info msg="loading plugin \"io.containerd.snapshotter.v1.zfs\"..." type=io.containerd.snapshotter.v1
time="2020-12-22T14:24:14.535549100Z" level=info msg="skip loading plugin \"io.containerd.snapshotter.v1.zfs\"..." error="path /var/lib/docker/containerd/daemon/io.containerd.snapshotter.v1.zfs must be a zfs filesystem to be used with the zfs snapshotter: skip plugin" type=io.containerd.snapshotter.v1
time="2020-12-22T14:24:14.535569500Z" level=info msg="loading plugin \"io.containerd.metadata.v1.bolt\"..." type=io.containerd.metadata.v1
time="2020-12-22T14:24:14.535655000Z" level=warning msg="could not use snapshotter devmapper in metadata plugin" error="devmapper not configured"
time="2020-12-22T14:24:14.535666700Z" level=info msg="metadata content store policy set" policy=shared
time="2020-12-22T14:24:14.543388600Z" level=info msg="loading plugin \"io.containerd.differ.v1.walking\"..." type=io.containerd.differ.v1
time="2020-12-22T14:24:14.543437600Z" level=info msg="loading plugin \"io.containerd.gc.v1.scheduler\"..." type=io.containerd.gc.v1
time="2020-12-22T14:24:14.543466400Z" level=info msg="loading plugin \"io.containerd.service.v1.introspection-service\"..." type=io.containerd.service.v1
time="2020-12-22T14:24:14.543517000Z" level=info msg="loading plugin \"io.containerd.service.v1.containers-service\"..." type=io.containerd.service.v1
time="2020-12-22T14:24:14.543529700Z" level=info msg="loading plugin \"io.containerd.service.v1.content-service\"..." type=io.containerd.service.v1
time="2020-12-22T14:24:14.543538300Z" level=info msg="loading plugin \"io.containerd.service.v1.diff-service\"..." type=io.containerd.service.v1
time="2020-12-22T14:24:14.543547500Z" level=info msg="loading plugin \"io.containerd.service.v1.images-service\"..." type=io.containerd.service.v1
time="2020-12-22T14:24:14.543555900Z" level=info msg="loading plugin \"io.containerd.service.v1.leases-service\"..." type=io.containerd.service.v1
time="2020-12-22T14:24:14.543564700Z" level=info msg="loading plugin \"io.containerd.service.v1.namespaces-service\"..." type=io.containerd.service.v1
time="2020-12-22T14:24:14.543589200Z" level=info msg="loading plugin \"io.containerd.service.v1.snapshots-service\"..." type=io.containerd.service.v1
time="2020-12-22T14:24:14.543601300Z" level=info msg="loading plugin \"io.containerd.runtime.v1.linux\"..." type=io.containerd.runtime.v1
time="2020-12-22T14:24:14.543816700Z" level=info msg="loading plugin \"io.containerd.runtime.v2.task\"..." type=io.containerd.runtime.v2
time="2020-12-22T14:24:14.543949500Z" level=info msg="loading plugin \"io.containerd.monitor.v1.cgroups\"..." type=io.containerd.monitor.v1
time="2020-12-22T14:24:14.544245600Z" level=info msg="loading plugin \"io.containerd.service.v1.tasks-service\"..." type=io.containerd.service.v1
time="2020-12-22T14:24:14.544273200Z" level=info msg="loading plugin \"io.containerd.internal.v1.restart\"..." type=io.containerd.internal.v1
time="2020-12-22T14:24:14.544328900Z" level=info msg="loading plugin \"io.containerd.grpc.v1.containers\"..." type=io.containerd.grpc.v1
time="2020-12-22T14:24:14.544342400Z" level=info msg="loading plugin \"io.containerd.grpc.v1.content\"..." type=io.containerd.grpc.v1
time="2020-12-22T14:24:14.544355300Z" level=info msg="loading plugin \"io.containerd.grpc.v1.diff\"..." type=io.containerd.grpc.v1
time="2020-12-22T14:24:14.544388800Z" level=info msg="loading plugin \"io.containerd.grpc.v1.events\"..." type=io.containerd.grpc.v1
time="2020-12-22T14:24:14.544400500Z" level=info msg="loading plugin \"io.containerd.grpc.v1.healthcheck\"..." type=io.containerd.grpc.v1
time="2020-12-22T14:24:14.544410100Z" level=info msg="loading plugin \"io.containerd.grpc.v1.images\"..." type=io.containerd.grpc.v1
time="2020-12-22T14:24:14.544418500Z" level=info msg="loading plugin \"io.containerd.grpc.v1.leases\"..." type=io.containerd.grpc.v1
time="2020-12-22T14:24:14.544426400Z" level=info msg="loading plugin \"io.containerd.grpc.v1.namespaces\"..." type=io.containerd.grpc.v1
time="2020-12-22T14:24:14.544434400Z" level=info msg="loading plugin \"io.containerd.internal.v1.opt\"..." type=io.containerd.internal.v1
time="2020-12-22T14:24:14.544594500Z" level=info msg="loading plugin \"io.containerd.grpc.v1.snapshots\"..." type=io.containerd.grpc.v1
time="2020-12-22T14:24:14.544619500Z" level=info msg="loading plugin \"io.containerd.grpc.v1.tasks\"..." type=io.containerd.grpc.v1
time="2020-12-22T14:24:14.544634200Z" level=info msg="loading plugin \"io.containerd.grpc.v1.version\"..." type=io.containerd.grpc.v1
time="2020-12-22T14:24:14.544663700Z" level=info msg="loading plugin \"io.containerd.grpc.v1.introspection\"..." type=io.containerd.grpc.v1
time="2020-12-22T14:24:14.544887300Z" level=info msg=serving... address=/var/run/docker/containerd/containerd-debug.sock
time="2020-12-22T14:24:14.544962300Z" level=info msg=serving... address=/var/run/docker/containerd/containerd.sock.ttrpc
time="2020-12-22T14:24:14.545031400Z" level=info msg=serving... address=/var/run/docker/containerd/containerd.sock
time="2020-12-22T14:24:14.545052600Z" level=info msg="containerd successfully booted in 0.039523s"
time="2020-12-22T14:24:14.550601900Z" level=info msg="parsed scheme: \"unix\"" module=grpc
time="2020-12-22T14:24:14.550628500Z" level=info msg="scheme \"unix\" not registered, fallback to default scheme" module=grpc
time="2020-12-22T14:24:14.550642900Z" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:///var/run/docker/containerd/containerd.sock  <nil> 0 <nil>}] <nil> <nil>}" module=grpc
time="2020-12-22T14:24:14.550649800Z" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
time="2020-12-22T14:24:14.551481200Z" level=info msg="parsed scheme: \"unix\"" module=grpc
time="2020-12-22T14:24:14.551539900Z" level=info msg="scheme \"unix\" not registered, fallback to default scheme" module=grpc
time="2020-12-22T14:24:14.551669400Z" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:///var/run/docker/containerd/containerd.sock  <nil> 0 <nil>}] <nil> <nil>}" module=grpc
time="2020-12-22T14:24:14.551705500Z" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
time="2020-12-22T14:24:14.628382700Z" level=info msg="Loading containers: start."
time="2020-12-22T14:24:14.628879000Z" level=warning msg="Running modprobe bridge br_netfilter failed with message: , error: exec: \"modprobe\": executable file not found in $PATH"
time="2020-12-22T14:24:14.688266300Z" level=info msg="Default bridge (docker0) is assigned with an IP address 172.18.0.0/16. Daemon option --bip can be used to set a preferred IP address"
time="2020-12-22T14:24:14.730182300Z" level=info msg="Loading containers: done."
time="2020-12-22T14:24:14.772404900Z" level=info msg="Docker daemon" commit=eeddea2 graphdriver(s)=overlay2 version=20.10.0
time="2020-12-22T14:24:14.772696700Z" level=info msg="Daemon has completed initialization"
time="2020-12-22T14:24:14.812249700Z" level=info msg="API listen on /var/run/docker.sock"
Creating empty configuration file: /home/octopus/.octopus/OctopusServer/Server/Server.linux.config
Saving instance: OctopusServer
Setting home directory to: /home/octopus/.octopus/OctopusServer/Server
Defaulting server node name to '79bbcaf19466'.

======== Initializing DB ========
Setting database connection string to: server=localhost,1433;database=octoDB;user=sa;password=********
========== SQL Database Connection Details ========
SQL Server: localhost,1433
SQL Database: octoDB
Authentication Type: SQL Server Credentials
User: sa

===================================================
Testing connection to the 'master' database...
Connection test to master timed out after trying 17 times over 00:01:00.6773117.
Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 40 - Could not open a connection to SQL Server)
   at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at Microsoft.Data.SqlClient.SqlConnection.Open()
   at Octopus.Core.RelationalStorage.SqlServerManager.TestConnection(Boolean throwException, String databaseName, Nullable`1 timeout) in C:\buildAgent\work\f014c79b193351c2\source\Octopus.Core\RelationalStorage\SqlServerManager.cs:line 326
ClientConnectionId:00000000-0000-0000-0000-000000000000
We are having trouble working with your SQL Database. This will usually be something you can fix. If not please contact support@octopus.com for help. Here are the error details: SQL Error 0 - A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 40 - Could not open a connection to SQL Server)
Microsoft.Data.SqlClient.SqlException
   at Octopus.Server.Commands.DatabaseCommand.Start() in C:\buildAgent\work\f014c79b193351c2\source\Octopus.Server\Commands\DatabaseCommand.cs:line 123

I am able to access the database with sqlcmd and even added outboundnetworkaccess = 1. I am running this on Ubuntu 18.04 and I have tried it on Windows as well without a container instance of MSSQL.

Thank you for any assistance.

Cheers,
Ian

Hi Ian,

Thanks for reaching out to us at Octopus Support!

Sorry you’re running into issues with your Docker-run Octopus Deploy instance. I’m going to see if I can reproduce this on my end and get back with you as soon as possible.

Regards,
Mallory

Hi Ian,

Thanks for your patience on this! I just completed my reproduction and the issue seems to be that you’re targeting localhost in your docker run versus the Docker container where the Octopus Server lives.

I was able to connect successfully to MSSQL from a Dockerized version of Octopus Server with the following configuration: sudo docker run --privileged --interactive --detach --name OctopusDeploy --publish 1322:8080 --env ACCEPT_EULA='Y' --env DB_CONNECTION_STRING='Server=172.17.0.1,1433;Database=octoDB;User=sa;Password=super_secret' octopusdeploy/octopusdeploy:2020.5.2.

I just ran ifconfig to get the IPv4 address for my Docker container and I plugged that in the Server param. If you give that a shot, you should be able to get a connection going from Docker to MSSQL.

Let me know how that goes for you!

Regards,
Mallory

Hi Mallory,
Yeah thanks that worked!
Thank you for the help.
Regards,
Ian

Hey Ian,

I’m going to jump in for Mallory as she is on Holiday.

Thanks for letting us know it worked!

I hope you have a great rest of your week.

Best,
Jeremy

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.