Keycloak running in docker and connecting to local mariaDB - docker

I try to setup keycloak as a docker container using a mariaDB Server which is installed on the host machine. The mariaDB Server should not run in a Docker container.
I try to run keycloak by this command:
docker run -d --name keycloak -p 8443:8443 -v /opt/keycloak/certs:/etc/x509/https --net staticNet --ip 172.18.0.10 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD='password' -e DB_VENDOR=mariadb -e DB_ADDR=host.docker.internal -e DB_DATABASE=keycloak -e DB_USERNAME=keycloak -e DB_PASSWORD='dbUserPassword' jboss/keycloak
The Network was created with: docker network create --subnet=172.18.0.0/16 staticNet
But keycload fails to start with error that it is not able to connect to the database host.
Is there something missing in my network Configuration? Or is something wrong with my docker run? Or do I need some special configuration for my mariaDB Server?

Related

How to set "xpack.security.enrollment.enabled" to "true for elasticsearch in Docker

This is how I start elasticsearch with Kibana in "Docker for Windows":
docker network create --driver bridge elastic
docker run -p 127.0.0.1:9200:9200 -p 127.0.0.1:9300:9300 --name elasticsearch -v elasticsearch-data:/usr/share/elasticsearch/data -e "discovery.type=single-node" -e ELASTIC_USER=Andreas -e ELASTIC_PASSWORD=Hirsebrei docker.elastic.co/elasticsearch/elasticsearch:8.5.2
docker run --name kib-01 -p 5601:5601 docker.elastic.co/kibana/kibana:8.5.3
This all runs fine and I can open the Kibana pagein the browser which requests an enrollment token.
I use the following from a command line to generate the enrollment token:
docker exec -it elasticsearch /bin/sh
then in the shell I do this:
cd /usr/share/elasticsearch/bin/
./elasticsearch-create-enrollment-token --scope kibana
which results in the following error message:
ERROR: [xpack.security.enrollment.enabled] must be set to `true` to create an enrollment token
Now I am lost.
Can someone please help me out and explain to me how to set [xpack.security.enrollment.enabled] to true?

Remote access to cassandra 4.0.1 using docker via cqlsh

My Environment:
Windows 10 Home
WSL2
Cassandra 4.0.1: Official Docker Image
Docker command:
docker run --name cassandra-node-0 -p 7000:7000 -p 7001:7001 -p 7199:7199 -p 9042:9042 -p 9160:9160 -e CASSANDRA_CLUSTER_NAME=MyCluster -e CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch -e CASSANDRA_DC=datacenter1 -e CASSANDRA_BROADCAST_ADDRESS=192.168.1.101 -d cassandra
CQLSH Command:
docker run -it -e CQLSH_HOST=$(docker inspect --format='{{ .NetworkSettings.IPAddress}}' cassandra-node-0) --name cassandra-client --entrypoint=cqlsh cassandra
I try to connect cassandra node using cqlsh where ubuntu in WSL2 in same pc.
I did not change all *.yaml file and only use Docker Env.
When I insert node's docker network ip to CQLSH_HOST, cqlsh is successfully connected node.
But, When I insert my private ip, public ip or 127.0.0.1, cqlsh is refused connection to node.
This shows the same issue when nodes from different networks connect.
I think I'm missing a setting of something Docker Env.
What settings am I missing?
[Update] I add some port fowarding rules in firewall but same issue.
[Update 2] docker ps -a result:
0.0.0.0:7000-7001->7000-7001/tcp, :::7000-7001->7000-7001/tcp, 0.0.0.0:7199->7199/tcp, :::7199->7199/tcp, 0.0.0.0:9042->9042/tcp, :::9042->9042/tcp, 0.0.0.0:9160->9160/tcp, :::9160->9160/tcp
Try adding --hostname and --network when you run Cassandra. For example:
$ docker run --rm -d
--name cassandra-node-0
--hostname cassandra-node-0
--network cassandra-node-0
You'll find that it's easier to connect via cqlsh by adding:
--network cassandra-node-0
-e CQLSH_HOST=cassandra-node-0
to your docker run command. Cheers!

Cannot connect to keycloak admin panel

I've followed this tutorial and run keycloak with postgres via Docker. Since port 8080 is already in use by my front-end app, it used 9990 instead.
As the logs say:
13:26:00,602 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
13:26:00,603 INFO [org.jboss.as] (Controller Boot Thread)
WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
But when I go to these urls through my browser, nothing happens. I've also tried going to http://127.0.0.1:9990/auth/admin/ and it doesn't work to. When I try to connect, nothing appears in my keycloak console.
I've followed the tutorial without any additional settings. What's wrong?
Firstly I create a user define network:
docker network create keycloak-network
Then I run postgres:
docker run -d --name postgres --net keycloak-network -e POSTGRES_DB=keycloak -e POSTGRES_USER=keycloak -e POSTGRES_PASSWORD=password postgres
And Finally Keycloak:
docker run --name keycloak --net keycloak-network jboss/keycloak
You need to publish ports (8080 for http, 8443 for https) of the Keycloak container + remap ports, because 8080 is already used on your machine. For example:
docker run --rm \
--name keycloak \
--net keycloak-network \
-e KEYCLOAK_USER=myadmin \
-e KEYCLOAK_PASSWORD=mypassword \
-p 9990:8080 \
-p 9991:8443 \
jboss/keycloak
Keycloak admin UI will be available on:
http://<ip of the host machine\>:9990/
https://<ip of the host machine\>:9991/ (self signed cert will be generated in this case, so you will need to approve TLS exception in the browser)
If someone else like me will start his way in Docker from installing Keycloak asap.
Full path to install Keycloak on Docker and then have access to web UI via port 9990 (you can change it in last command):
docker network create keycloak-network
docker run -d --name postgres --net keycloak-network -e POSTGRES_DB=keycloak -e POSTGRES_USER=keycloak -e POSTGRES_PASSWORD=password postgres
docker run --rm --name keycloak --net keycloak-network -e KEYCLOAK_USER=myadmin -e KEYCLOAK_PASSWORD=mypassword -e DB_USER=keycloak -e DB_PASSWORD=password -p 9990:8080 -p 9991:8443 jboss/keycloak
Difference from topickstarter's and previous answer is avoiding of error below:
"WFLYCTL0113: '' is an invalid value for parameter user-name
by providing DB username and password in last command.

pact-broker docker image is not running after restarting docker machine

I am using Postgres image and past broker image in my docker machine for setting up pact broker.
here are 4 steps that have mentioned :
1.$ docker run --name pactbroker-db -e POSTGRES_PASSWORD=ThePostgresPassword -e POSTGRES_USER=admin -e PGDATA=/var/lib/postgresql/data/pgdata -v /var/lib/postgresql/data:/var/lib/postgresql/data -d postgres
2.$ docker run -it --link pactbroker-db:postgres --rm postgres sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U admin'
3.
CREATE USER pactbrokeruser WITH PASSWORD 'TheUserPassword';
CREATE DATABASE pactbroker WITH OWNER pactbrokeruser;
GRANT ALL PRIVILEGES ON DATABASE pactbroker TO pactbrokeruser;
4. docker run --name pactbroker --link pactbroker-db:postgres -e PACT_BROKER_DATABASE_USERNAME=pactbrokeruser -e PACT_BROKER_DATABASE_PASSWORD=TheUserPassword -e PACT_BROKER_DATABASE_HOST=postgres -e PACT_BROKER_DATABASE_NAME=pactbroker -d -p 80:80 dius/pact_broker
after running this 4 command when I am opening Hal browser in my local system it is working pretty fine. Now I am stopping 2 docker containers pactbroker-db and pactbroker and stopping docker machine.
After sometime I am restarting docker machine and starting the containers by
$docker start pactbroker-db and $docker start pactbroker .
containers are getting started but when opening HAL browser I am getting the error "We're sorry, but something went wrong." screenshot attached.
Is there something wrong when I am starting the docker 2nd time?enter image description here
This has been resolved by using container given in https://github.com/DiUS/pact_broker-docker and using proper environment variables in docker-compose.yml of this project.

Docker port rewrite

I used docker for wordpress like this:
Create volume containers:
$ docker create -v /home/juanda/project/bbdd:/var/lib/mysql --name bbdd ubuntu /bin/true
$ docker create -v /home/juanda/project/web:/var/www/html --name web ubuntu /bin/true
Mysql container:
$ docker run --volumes-from bbdd --name mysql -e MYSQL_ROOT_PASSWORD="xxxx" -d mysql
Apache, php and wordpress container:
$ docker run --volumes-from web --name apache --link mysql:mysql -d -p 5555:80 wordpress
I installed and ran everything ok. If I remove apache container (stop and rm) and I launch it awain in another port (8080 instead of 5555), it rewrites url in navigator to 5555 and I get a connection error. Any idea?

Resources