You are (running) a docker-image .. and the (running) docker-image does NOT understand connection strings like
localhost
localhost\MyInstance
You need the docker-running-image to be able to talk to your local-setup. You could use the IP address of your local machine. BUT fortunately, docker has a built in ALIAS for "the host machine that spawned me (the docker image)".
see:
https://docs.docker.com/desktop/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host
I want to connect from a container to a service on the host The host
has a changing IP address (or none if you have no network access). We
recommend that you connect to the special DNS name
host.docker.internal which resolves to the internal IP address used by
the host. This is for development purpose and does not work in a
production environment outside of Docker Desktop.
Below shows that alias, and how it would be used for a Ms-Sql-Server connection string.
Data Source=host.docker.internal:1433;DatabaseName=MyDatabase;
or
"server=host.docker.internal\MyInstance;database=MyDatabase;"
You may need to use sql authentication as well, to jump "from docker" to your local machine. (The docker-running-image will NOT understand "integrated security" in the local developer understanding of integrated-security)
You have to treat the docker running images AS ANOTHER MACHINE, so if you have a localhost\MyInstance sql server, you'll have to open up remote tcp connections to it as well.
General rule of thumb.
A container running on your machine...is NOT like local code..when it
comes to hitting things like a db-server, local-sftp, etc.
If you do not use sql-authentication, you'll probably get an error like this:
Cannot authenticate using Kerberos. Ensure Kerberos has been initialized on the client with 'kinit' and a Service Principal Name has been registered for the SQL Server to allow Kerberos authentication.
ErrorCode=InternalError, Exception=Interop+NetSecurityNative+GssApiException: GSSAPI operation failed with error - Unspecified GSS failure. Minor code may provide more information (SPNEGO cannot find mechanisms to negotiate).
BONUS:
Below is a bookmarked article I have for allowing remote connections to your LOCAL machine.
https://knowledgebase.apexsql.com/configure-remote-access-connect-remote-sql-server-instance-apexsql-tools/