Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: MSSQL Cannot run 'SELECT 1': container is not ready #666

Closed
grieve54706 opened this issue Aug 6, 2024 · 4 comments · Fixed by #685 or #683
Closed

Bug: MSSQL Cannot run 'SELECT 1': container is not ready #666

grieve54706 opened this issue Aug 6, 2024 · 4 comments · Fixed by #685 or #683

Comments

@grieve54706
Copy link
Contributor

Describe the bug

Microsoft changes the mssql-tools folder name to mssql-tools18 at 2019-latest and 2022-latest. Testcontainer could not use the right path to check database status by mssql tool.

status, _ = self.exec(f"/opt/mssql-tools/bin/sqlcmd -U {self.username} -P {self.password} -Q 'SELECT 1'")

Relate microsoft/mssql-docker#892 (comment)

To Reproduce

from testcontainers.mssql import SqlServerContainer

mssql = SqlServerContainer("mcr.microsoft.com/mssql/server:2019-latest").start()

Solution
We need to determine the exact location of the MSSQL tool before utilizing it.

@kiview
Copy link
Member

kiview commented Aug 6, 2024

This issue is also present in other Testcontainers implementations: testcontainers/testcontainers-dotnet#1220

@alexanderankin
Copy link
Collaborator

ok so based on the quoting this is being executed by the container's shell. so it can simply be replaced with $(which sqlcmd) except that it may not be in the PATH:

$ docker image inspect mcr.microsoft.com/mssql/server:2019-latest | jq .[].Config.Env
[
  "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
]

so how should we fix?

/opt/mssql-tools*/bin/sqlcmd

this does appear to work:

$ docker run --rm -it --entrypoint 'bash' mcr.microsoft.com/mssql/server:2019-latest
mssql@5d2990b93a8a:/$ file /opt/mssql-tools*/bin/sqlcmd
/opt/mssql-tools18/bin/sqlcmd: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.24, BuildID[sha1]=a341d98e7522c347f723c8f11a1170d9cdf8ad7a, stripped
mssql@5d2990b93a8a:/$ /opt/mssql-tools*/bin/sqlcmd



^CCanceling connection...
mssql@5d2990b93a8a:/$

@grieve54706
Copy link
Contributor Author

so how should we fix?

/opt/mssql-tools*/bin/sqlcmd

this does appear to work:

$ docker run --rm -it --entrypoint 'bash' mcr.microsoft.com/mssql/server:2019-latest
mssql@5d2990b93a8a:/$ file /opt/mssql-tools*/bin/sqlcmd
/opt/mssql-tools18/bin/sqlcmd: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.24, BuildID[sha1]=a341d98e7522c347f723c8f11a1170d9cdf8ad7a, stripped
mssql@5d2990b93a8a:/$ /opt/mssql-tools*/bin/sqlcmd



^CCanceling connection...
mssql@5d2990b93a8a:/$

Cool. This is an elegant solution.

@grieve54706
Copy link
Contributor Author

Hi @alexanderankin, unfortunately, docker execute run /opt/mssql-tools*/bin/sqlcmd will get error

b'OCI runtime exec failed: exec failed: unable to start container process: exec: "/opt/mssql-tools*/bin/sqlcmd": stat /opt/mssql-tools*/bin/sqlcmd: no such file or directory: unknown\r\n'

alexanderankin pushed a commit that referenced this issue Sep 3, 2024
🤖 I have created a release *beep* *boop*
---


##
[4.8.1](testcontainers-v4.8.0...testcontainers-v4.8.1)
(2024-08-18)


### Bug Fixes

* **generic:** Update the FastAPI install on genric module doctest
samples
([#686](#686))
([5216b02](5216b02))
* **mssql:** use glob to find mssql-tools folder since it moves
([#685](#685))
([4912725](4912725)),
closes
[#666](#666)
* wait_for_logs can now fail early when the container stops
([#682](#682))
([925329d](925329d))


### Documentation

* Add a more advance usecase documentation for ServerContainer
([#688](#688))
([2cf5a9f](2cf5a9f))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants