Cannot Connect Keycloak docker to SQL database - sql-server

I'm trying to connect Keycloak with docker to a SQL Server database located on another server, but I'm not getting a connection.
This is the command I'm typing:
docker run --name keycloak \
--net keycloak-network \
-p 8080:8080 \
-e DB_VENDOR=mssql \
-e DB_USER=*** \
-e DB_PASSWORD=*** \
-e DB_ADDR=172.... \
-e DB_DATABASE=Keycloak \
-e KEYCLOAK_USER=user \
-e KEYCLOAK_PASSWORD=password \
jboss/keycloak
Could someone help me to solve it please.
Apparently it could be some SSL and RSA 1024 bitkey error
Caused by: java.security.cert.CertificateException: Certificates do not conform to algorithm constraints
at java.base/sun.security.ssl.AbstractTrustManagerWrapper.checkAlgorithmConstraints(SSLContextImpl.java:1681)
at java.base/sun.security.ssl.AbstractTrustManagerWrapper.checkAdditionalTrust(SSLContextImpl.java:1606)
at java.base/sun.security.ssl.AbstractTrustManagerWrapper.checkServerTrusted(SSLContextImpl.java:1550)
at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts(CertificateMessage.java:638)
... 78 more
Caused by: java.security.cert.CertPathValidatorException: Algorithm constraints check failed on keysize limits: RSA 1024 bit key used with certificate: CN=SSL_Self_Signed_Fallback
at java.base/sun.security.util.DisabledAlgorithmConstraints$KeySizeConstraint.permits(DisabledAlgorithmConstraints.java:889)
at java.base/sun.security.util.DisabledAlgorithmConstraints$Constraints.permits(DisabledAlgorithmConstraints.java:507)
at java.base/sun.security.util.DisabledAlgorithmConstraints.permits(DisabledAlgorithmConstraints.java:247)
at java.base/sun.security.util.DisabledAlgorithmConstraints.permits(DisabledAlgorithmConstraints.java:193)
at java.base/sun.security.provider.certpath.AlgorithmChecker.check(AlgorithmChecker.java:292)
at java.base/sun.security.ssl.AbstractTrustManagerWrapper.checkAlgorithmConstraints(SSLContextImpl.java:1677)
... 81 more
These are the errors that appear.

Related

When docker deploys the openGauss database, how to change one master one standby to one master two standby?

When docker deploys the openGauss database, how to change one master one standby to one master two standby?
docker run --network opengaussnetwork --ip $MASTER_IP --privileged=true \
--name $MASTER_NODENAME -h $MASTER_NODENAME -p $MASTER_HOST_PORT:$MASTER_HOST_PORT -d \
-e GS_PORT=$MASTER_HOST_PORT \
-e OG_SUBNET=$OG_SUBNET \
-e GS_PASSWORD=$GS_PASSWORD \
-e NODE_NAME=$MASTER_NODENAME \
-e REPL_CONN_INFO="replconninfo1 = 'localhost=$MASTER_IP localport=$MASTER_LOCAL_PORT localservice=$MASTER_HOST_PORT remotehost=$SLAVE_1_IP remoteport=$SLAVE_1_LOCAL_PORT remoteservice=$SLAVE_1_HOST_PORT'\n" \
enmotech/opengauss:$VERSION -M primary \
|| {
echo ""
echo "ERROR: OpenGauss Database Master Docker Container was NOT successfully created."
exit 1
}
echo "OpenGauss Database Master Docker Container created."
Add the replication channels 'replconninfo2' to the three nodes of the openGauss database

Data loss on Azure Container Instance with mounted volume

I just created a container instance on azure with an sql server docker image and a mounted file sharing storage as a volume. The fact is that the container got stucked, so I restarted it.
After restart, all data was gone. When I restart a docker container locally, data keep existing because of volumes so I cannot understand the behaviour on azure.
Any clue about this?
Here is the cli command I run to create the container
az container create --resource-group myresource-rg \
--name project-test-db \
--image mcr.microsoft.com/mssql/server:2019-latest \
--location westus2 \
--ports 1433 \
--memory 5 \
--environment-variables SA_PASSWORD=Password ACCEPT_EULA=Y \
--ip-address public \
--azure-file-volume-account-name projectteststorageacc \
--azure-file-volume-account-key \MyKey \
--azure-file-volume-share-name project-test-file-share \
--azure-file-volume-mount-path /databases
Try editing your command as below
Use " " for around ACCEPT_EULA=Y and key-value pair as below. And replace SA_PASSWORD with MSSQL_SA_PASSWORD
--environment-variables "MSSQL_SA_PASSWORD=Password" "ACCEPT_EULA=Y" \
Required setting for the SQL Server image, a strong password that is at least 8 characters and meets the SQL Server password requirements. Given if you have set appropriate strong password and storage key already, the below commands works just fine for me. If the password doesn't meet SQL standards this container fails (restart loop).
PS /home/karthik> $Password = "MyStrongPassword"
PS /home/karthik> $key = "FO/R6WkZELhMzX02wi9KahtLtKppoSIJg/EcJLEnZajRm2uxXs0sb/APaCk1eRsNW31yijSjS1hFm5Rd4rdTew=="
az container create --resource-group Myrg \
--name project-test-db \
--image mcr.microsoft.com/mssql/server:2019-latest \
--location westus2 \
--ports 1433 \
--memory 5 \
--environment-variables "SA_PASSWORD=$Password" "ACCEPT_EULA=Y" \
--ip-address public \
--azure-file-volume-account-name kteststoragee \
--azure-file-volume-account-key $key \
--azure-file-volume-share-name ktestfs2 \
--azure-file-volume-mount-path /databases
When you have a misbehaving container in Azure Container Instances, start by viewing its logs with az container logs, and stream its standard out and standard error with az container attach.
The az container attach command provides diagnostic information during container startup. Once the container has started, it streams STDOUT and STDERR to your local console.
Refer: Quickstart: Run SQL Server container images with Docker and Docker run command fails with Accept-Eula Agreement error #199

Failed to connect to docker hosted MSSQL

I have a problem followng [this tutorial](https://hub.docker.com/r/microsoft/mssql-server-linux/
) where I try to connect to my docker hosted MSSQL via sqlcmd.
I executed the following in PowerShell from windows:
docker run -e 'ACCEPT_EULA=Y' --name mssql -e \
'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -it \
-d microsoft/mssql-server-linux:latest /bin/bash
Note: "-it" and "/bin/bash" is added due to docker will be stopped automatically if there is no any activity detected.
I ran docker container ls -a to verify it is running:
docker container Is -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
92cfc504ab70 microsoft/mssql-server-linux:latest "/bin/bash" 27 minutes ago Up 27 minutes 0.0.0.0:1433->1433/tcp mssql
I ran telnet local-ip:1433 on my host, it is working fine.
Problem lies when I do the following:
docker exec -it mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U sa \
-P yourStrong(!)Password
Error:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout
expired. Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP
Provider: Error code 0x2749. Sqlcmd: Error: Microsoft ODBC Driver 17
for SQL Server : A network-related or instance-specific error has
occurred while establishing a connection to SQL Server. Server is not
found or not accessible. Check if instance name is correct and if SQL
Server is configured to allow remote connections. For more information
see SQL Server Books Online..
I also tried to connect in using powershell via my host
Link:https://learn.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker
Command:
sqlcmd -S 192.168.0.110,1433 -U SA -P yourStrong(!)Password
Note: 192.168.0.110(got this from running ipconfig in host machine.)
Any help ?
I found out the problems after some trials and errors, and re-reading the documents. I should use double quotes for the arguments when I executed my command in PowerShell.
I was looking into the wrong direction. Initially I executed the command:
docker run -e 'ACCEPT_EULA=Y' --name mssql -e \
'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -d \
microsoft/mssql-server-linux:latest
Container stopped automatically by itself every time it starts.
Then, I did some googling and found:
docker run -e 'ACCEPT_EULA=Y' --name mssql -e \
'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -it -d \
microsoft/mssql-server-linux:latest /bin/bash
It seemed fine on the surface. It got executed successfully in PowerShell. It didn't stop automatically anymore.If I dig deeper using
docker container logs mssql
to see the log for mssql. No error given, just that I don't see a lots of info given, which led me to think that there were no problems in my command.
But the right way to run these commands is using double quotes.
Link: https://hub.docker.com/r/microsoft/mssql-server-linux/
IMPORTANT NOTE: If you are using PowerShell on Windows to run these commands use double quotes instead of single quotes.
E.g.
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=YourStrong!Passw0rd" -p 1401:1433 --name sql1 -d microsoft/mssql-server-linux:2017-latest
I am also able to login using SSMS with:
Server name: Hostip,1401
Username: sa
Password:yourpassword
Try 127.0.0.1 or 0.0.0.0 instead of localhost
For example :
docker exec -it mssql /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -U sa -P 'yourStrong(!)Password'
docker run command syntax is the following:
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
When you execute the command:
docker run -e 'ACCEPT_EULA=Y' --name mssql -e 'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -it -d microsoft/mssql-server-linux:latest /bin/bash
/bin/bash in the end overrides CMD layer defined in the Dockerfile of microsoft/mssql-server-linux image.
So, just start a container without any additional command in the end:
$ docker run -e 'ACCEPT_EULA=Y' --name mssql -e 'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -it -d microsoft/mssql-server-linux:latest
And now you are able to access a MSSQL:
$ docker exec -it mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'yourStrong(!)Password'
1>
I'm new to Docker and I also I had the same issue when I try to connect to the SQL Server container from my application(or sqlcmd app container from Microsoft) which is also running in another Docker container. It looks like each container gets its own subnet IP address, so 'localhost' would never work if you're trying to connect to the SQL from another container.
The command below will give you the full list of IP addresses in the bridge network. You can specify the IP directly in the connection string.
docker network inspect bridge
From your message, it looks the server is not configured to access remotely. Can you follow the way mentioned below to enable it?
Using SSMS (SQL Server Management studio):
In Object Explorer, right-click a server and select Properties.
Click the Connections node.
Under Remote server connections, select the Allow remote connections to this server check box.
Thanks,
Ananda Kumar J.

Docker and SQL Server Linux - Error 9002. The transaction log for database master is full due to NOTHING

I use Docker without Hyper-V with VirtualBox and Docker VM on Windows 10 Home edition.
I have the following Docker build file:
FROM repositoryname/mssql-server-linux:test-db
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . /usr/src/app
# start sql, setup db
RUN /opt/mssql/bin/sqlservr & sleep 15s && \
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P pass -d master -i /usr/src/app/setup_db_1.sql && \
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P pass -d master -i /usr/src/app/setup__db_2.sql
Right now MS SQL Server fails during startup with the following error:
Error 9002. The transaction log for database master is full due to NOTHING
Is there anything I can do (for example add some instructions to my Docker build file) in order to prevent this error?
Also, I found the similar topic here https://social.msdn.microsoft.com/Forums/en-US/ca65a3e2-2f30-4641-a7ea-d3998c8dd8a7/the-transaction-log-for-database-master-is-full-due-to-nothing-during-updade?forum=sqlsetupandupgrade but unfortunately without the proper answer right now.

How can I restore a database to a influxdb container

Sorry for my ignorance. I have influx db running on docker with docker-compose as below.
influxdb:
image: influxdb:alpine
ports:
- 8086:8086
volumes:
- ./influxdb/config/influxdb.conf:/etc/influxdb/influxdb.conf:ro
- ./influxdb/data:/var/lib/influxdb
I need to restore the backup of a database from remote server to this Influxdb container. I have taken the backup as below from remote server.
influxd backup -database tech_db /tmp/tech_db
I read the documentation and couldn't find a way to restore the DB to docker container.Can anyone give me a pointer to how to do this.
I have also had the same issue. Looks like it is impossible because you are not able to kill influxd process in a container.
# Restoring a backup requires that influxd is stopped (note that stopping the process kills the container).
docker stop "$CONTAINER_ID"
# Run the restore command in an ephemeral container.
# This affects the previously mounted volume mapped to /var/lib/influxdb.
docker run --rm \
--entrypoint /bin/bash \
-v "$INFLUXDIR":/var/lib/influxdb \
-v "$BACKUPDIR":/backups \
influxdb:1.3 \
-c "influxd restore -metadir /var/lib/influxdb/meta -datadir /var/lib/influxdb/data -database foo /backups/foo.backup"
# Start the container just like before, and get the new container ID.
CONTAINER_ID=$(docker run --rm \
--detach \
-v "$INFLUXDIR":/var/lib/influxdb \
-v "$BACKUPDIR":/backups \
-p 8086 \
influxdb:1.3
)
More information is here

Resources