Skip to content

Commit f7c584e

Browse files
committed
fix docker compose for mssql
1 parent 203c51f commit f7c584e

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

docker-compose.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,32 @@ services:
77
volumes:
88
- .:/var/www
99
depends_on:
10-
- ${COMPOSE_PROFILES-postgres}
10+
mssql: { condition: service_healthy }
11+
# [ "${COMPOSE_PROFILES-postgres}" ]
1112
environment:
12-
DATABASE_URL: ${COMPOSE_PROFILES-postgres}://root:secret@${COMPOSE_PROFILES:-postgres}/sqlpage
13+
DATABASE_URL: ${COMPOSE_PROFILES-postgres}://root:Password123!@${COMPOSE_PROFILES:-postgres}/sqlpage
1314
postgres:
1415
profiles: ["postgres"]
1516
ports: ["5432:5432"]
1617
image: postgres
1718
environment:
1819
POSTGRES_USER: root
1920
POSTGRES_DB: sqlpage
20-
POSTGRES_PASSWORD: secret
21+
POSTGRES_PASSWORD: Password123!
2122
mysql:
2223
profiles: ["mysql"]
2324
ports: ["3306:3306"]
2425
image: mysql
2526
environment:
26-
MYSQL_ROOT_PASSWORD: secret
27+
MYSQL_ROOT_PASSWORD: Password123!
2728
MYSQL_DATABASE: sqlpage
2829
mssql:
2930
profiles: ["mssql"]
3031
ports: ["1433:1433"]
31-
build: { context: "mssql" }
32+
build: { context: "mssql" }
33+
healthcheck:
34+
test: /opt/mssql-tools/bin/sqlcmd -S localhost -U root -P "Password123!" -Q "SELECT 1" -b -o /dev/null
35+
interval: 10s
36+
timeout: 3s
37+
retries: 10
38+
start_period: 10s

mssql/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ WORKDIR /usr/config
77

88
# Bundle config source
99
COPY entrypoint.sh /usr/config/entrypoint.sh
10-
COPY configure-db.sh /usr/config/configure-db.sh
1110
COPY setup.sql /usr/config/setup.sql
1211

1312
# Grant permissions for to our scripts to be executable
1413
USER root
1514
RUN chmod +x /usr/config/entrypoint.sh
16-
RUN chmod +x /usr/config/configure-db.sh
1715
RUN chown 10001 /usr/config/entrypoint.sh
18-
RUN chown 10001 /usr/config/configure-db.sh
1916
USER 10001
2017

2118
ENV SA_PASSWORD="Password123!"
2219
ENV ACCEPT_EULA="Y"
2320

21+
HEALTHCHECK --interval=10s --timeout=3s --start-period=10s --retries=10 \
22+
CMD sqlcmd -S localhost -U root -P "Password123!" -Q "SELECT 1" || exit 1
23+
2424
ENTRYPOINT ["/usr/config/entrypoint.sh"]

mssql/configure-db.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

mssql/entrypoint.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
#!/usr/bin/env bash
22

3-
# Start the script to create the DB and user
4-
/usr/config/configure-db.sh &
3+
/opt/mssql/bin/sqlservr &
4+
pid=$!
55

6-
# Start SQL Server
7-
/opt/mssql/bin/sqlservr
6+
# Wait 15 seconds for SQL Server to start up
7+
sleep 15
8+
9+
# Run the setup script to create the DB and the schema in the DB
10+
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$SA_PASSWORD" -d master -i setup.sql
11+
12+
# Wait for sqlservr to exit
13+
wait -n $pid

mssql/setup.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ GO
77
USE sqlpage;
88
GO
99

10-
CREATE LOGIN root WITH PASSWORD = 'secret';
11-
CREATE USER root FOR LOGIN MyUser;
10+
CREATE LOGIN root WITH PASSWORD = 'Password123!';
11+
CREATE USER root FOR LOGIN root;
1212
GO

0 commit comments

Comments
 (0)