-
Notifications
You must be signed in to change notification settings - Fork 766
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
Healthcheck #133
Comments
Yeah, now that we have sqlcmd in the image this should be much easier. I'll put it on our backlog internally. If you need something sooner, I'd suggest creating your own image FROM ours and specifying a HEALTCHECK that uses sqlcmd with -q to execute a simple query periodically like 'SELECT 1'. |
I too am having an issue where the docker image crashes, but continues to output lines of logging, which prevents my internal hung-build-killer tool to detect that something went wrong.
having a healthcheck mechanism in the case of this would be great. |
I get the same crash / error after using netcat to ascertain when the process has started listening on port 1433 |
This is super useful in order to avoid having to develop custom poll and wait script to check whether the DB is up in order to be able to start other activities. |
Dockerfile: FROM microsoft/mssql-server-linux
HEALTHCHECK --interval=10s --timeout=3s --start-period=10s --retries=10 \
CMD sqlcmd -S localhost -U sa -P ${SA_PASSWORD} -Q "SELECT 1" || exit 1 |
It should be
Because sqlcmd is not on PATH |
Is there a simple way to use HEALTHCHECK? |
Update 2024
|
Everything that is written above must be changed:
in Dockerfile:
|
I'm curious here, why do we need to have
https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility?view=sql-server-ver15#syntax |
Yes, |
These solution don't take into account that during database migration after an update, the database can be locked for several minutes. To the developers: Is it possible to take that into account? Does sql-server have an idiomatic way to determine that it is currently upgrading databases? Are you maybe working on a HEALTHCHECK command that is working with that scenario? The best idea so far to work around this is to add |
Thanks @mrlioncub 🎉 I was searching for a solution for using the image in a GitHub Action and the healthcheck wasn't working...thankfully Google found your comment. Passing name: CI
on: push
jobs:
test:
name: Test
runs-on: ubuntu-latest
env:
DB_USER: SA
DB_PASSWORD: yourStrongP@ssword
DB_NAME: your_db
services:
mssql:
image: mcr.microsoft.com/mssql/server:2017-latest-ubuntu
env:
ACCEPT_EULA: Y
SA_PASSWORD: ${{ env.DB_PASSWORD }}
MSSQL_PID: Express
DB_USER: ${{ env.DB_USER }}
DB_NAME: ${{ env.DB_NAME }}
ports:
- 1433/tcp
options: >-
--health-cmd "/opt/mssql-tools/bin/sqlcmd -U $DB_USER -P $SA_PASSWORD -Q 'select 1' -b -o /dev/null"
--health-interval 60s
--health-timeout 30s
--health-start-period 20s
--health-retries 3
steps:
- name: Create Database
run: |
docker exec $(docker ps -alq) /opt/mssql-tools/bin/sqlcmd -U "$DB_USER" -P "$DB_PASSWORD" -Q "CREATE DATABASE $DB_NAME;"
- uses: actions/checkout@v2
- name: Setup Node Package Cache
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
- name: Install
run: |
npm ci --prefer-offline --no-audit
- name: Test
env:
DB_HOST: localhost
DB_PORT: ${{ job.services.mssql.ports[1433] }}
DB_USER: ${{ env.DB_USER }}
DB_PASSWORD: ${{ env.DB_PASSWORD }}
DB_NAME: ${{ env.DB_NAME }}
run: |
npm test |
yes ,I have the same problem,use these can't resolve. how to config sqlserver healthycheck? |
BEST PRACTICE
|
I disagree with the "best practice" of using If you do not include {
"Health": {
"Status": "unhealthy",
"FailingStreak": 1,
"Log": [
{
"Start": "2023-05-23T05:41:54.699717693Z",
"End": "2023-05-23T05:41:54.827199774Z",
"ExitCode": 1,
"Output": "Msg 102, Level 15, State 1, Server 0999316e8300, Line 1\nIncorrect syntax near 'Error'.\n"
}
]
}
} |
Hi, |
You have two options here: a) use SQLCMDPASSWORD environment variable to pass the password |
since Can someone please provide a command that will work with whatever flavour of linux I realize it's a different image, but the ask is fairly generic: how does one test for port being open, and accepting connections w/o using specific tooling such as |
@clearwaterstream Taking inspiration from StackOverflow [1], I was able to use this since healthcheck:
test: timeout 1 bash -c 'cat < /dev/null > /dev/tcp/127.0.0.1/1433' |
I want to give my own version using SQLCMDPASSWORD environment... |
I've created a gist with latest mmsql ( https://gist.github.com/belgattitude/9979e5501d72ffa90c9460597dee8dca # Create and .env.mssql.development file with
#
# # @link https://learn.microsoft.com/en-us/sql/relational-databases/collations/collation-and-unicode-support?view=sql-server-ver15#utf8
# MSSQL_COLLATION=LATIN1_GENERAL_100_CI_AS_SC_UTF8
# MSSQL_SA_PASSWORD=AStrongPwd1456
# @link https://hub.docker.com/r/microsoft/mssql-server
# MSSQL_PID=Developer
# ACCEPT_EULA=Y
# TZ=Etc/UTC
#
name: example-mssql
services:
mssql:
container_name: example-mssql
image: mcr.microsoft.com/mssql/server:2022-CU16-ubuntu-22.04
# Only when docker is running as "root".
cap_add: ['SYS_PTRACE']
ports:
- '1433:1433'
env_file:
- .env.mssql.development
networks:
- example-mssql
volumes:
- example-mssql:/var/opt/mssql:rw
restart: no
healthcheck:
# -C disable checks for encryption
test: /opt/mssql-tools18/bin/sqlcmd -S localhost -C -U sa -P "$$MSSQL_SA_PASSWORD" -Q "SELECT 1" -b -o /dev/null
interval: 1s
timeout: 30s
retries: 30
start_period: 5s
volumes:
example-mssql:
networks:
example-mssql:
driver: bridge
enable_ipv6: false |
If possible, be compliant to the correct syntax for CMD or CMD-SHELL, see docker compose reference or SHELL/EXEC in Dockerfile reference, which is the preferred way: test: ["CMD-SHELL", "/opt/mssql-tools18/bin/sqlcmd -C -S localhost -U sa -P $$MSSQL_SA_PASSWORD -Q 'SELECT 1'"] or, if no variable subsitution is needed: test: ["CMD", "/opt/mssql-tools18/bin/sqlcmd", "-C", "-S", "localhost", "-U", "sa", "-P", "<YourStrong@Passw0rd>", "-Q", "SELECT 1"] Nothing wrong with your solution, I'm justing being picky here :) |
I couldn't make it work but I'm interested if you have an example, tried:
|
If you're going for variable substitution, you'll need to use CMD-SHELL syntax. |
This had worked for me 👍 services: |
Would it be possible to implement Docker's HEALTHCHECK command?
The text was updated successfully, but these errors were encountered: