0

I have 2 docker containers that host their own server. I also have a 3rd docker container that hosts a SQL Server database. Each server accesses this database.

My DB docker container is configured as so in the docker-compose.yml:

my-db:
     image: microsoft/mssql-server-linux:latest
     environment:
       - ACCEPT_EULA=Y
       - SA_PASSWORD=******
     ports:
       - "1433:1433"

Each servers connection string (They are .NET servers) are

ConnectionStrings__Default=data source=my-db;initial catalog=TestDb;persist security info=True;user id=SA;password=******;

When I run my tests, I get a log from the docker container for the DB that says it's setting SINGLE_USER mode on. This obviously breaks my tests because both servers have to access it.

I tried using a DB browser to set MULTI_USER on which worked... until the tests started... Then the db or something in the test suite switched it back to SINGLE_USER.

How do I configure this through the docker compose, dockerfiles or anything else to NOT set SINGLE_USER mode on or specifically set MULTI_USER mode on?

In case it matters: I'm also using Selenium for tests and circleci for test automation.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ian Kirkpatrick
  • 1,861
  • 14
  • 33
  • I don't see a volume specification which means it's using local writeable storage which is not really designed for persistent data. i don't know for certain this is the reason for single-user mode but I'm thinking it is related. Try using a volume with your container. – user1443098 Jun 18 '19 at 15:29
  • A volume? what would I sync it to? The DB only resides in the docker container. I assume you mean a volume on my DB docker container to something on my host comp? – Ian Kirkpatrick Jun 18 '19 at 15:33
  • Must you really use the SA account for your connection? – Wes H Jun 18 '19 at 17:49
  • @WesH for the container, yes. SA is the only account configured. Of course after login, you can create more – user1443098 Jun 18 '19 at 17:51
  • @WesH I guess. I'm new to this project and team so I have no idea why they chose that user. It wasn't my call – Ian Kirkpatrick Jun 18 '19 at 17:51
  • @IanKirkpatrick Since it's a docker image, that's the way MS built it. Of course you should always use a secure PW for sa, at least for prod deployments. For dev it is not always such a big concern. – user1443098 Jun 18 '19 at 19:16

1 Answers1

0

After scouring the code base I found it actually had nothing to do with configuration. I am using Entity Framework and the unit tests deleted and remigrated the database after each test. Calling the migrate command put the database into SINGLE_USER mode. I found this out when I removed the migrate call out of curiosity and lo and behold, no SINGLE_USER mode was set.

I assume the migrate call (myDbContext.Database.Migrate()) sets the mode so that it kicks other listeners out so as not to cause conflicts in the middle of migrations. But that's just a guess. I couldn't find the true answer as to why online.

So in short, the solution to this is that the code base was setting the SINGLE_USER mode, I just had to find the call.

Ian Kirkpatrick
  • 1,861
  • 14
  • 33