greenmail - keycloak connection doesn't work - keycloak

I'm trying to write some integration tests on my keycload flows.
To validate the registration and password forgotten mails, I would like to use greenmail.
my docker configuration of greenmail (within docker compose):
greenmail:
image: greenmail/standalone:1.5.7
environment:
- GREENMAIL_OPTS=-Dgreenmail.setup.test.all -Dgreenmail.hostname=0.0.0.0 -Dgreenmail.auth.disabled -Dgreenmail.verbose
ports:
- "3025:3025"
- "3143:3143"
And my keycloak email config:
when I click on "test connection", it doesn't work and I get in my logs:
error message (for those who can't open/display the image):
Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 3025; timeout 1000;
nester exception is: Connection refused
someone knows what I'm missing?

the issue wasn't greenmail or keycloak, but docker
=> localhost, which was used in the keycloak config, is the localhost mapping of the keycloak docker container, not of the docker host (i.e. the system running it).
changing the smtp host of keycloak to 'host.docker.internal' solved the issue => this is the way to get the host ip address within a docker container

Related

Docker cannot access an external SMTP server

I have an SMTP server running on a machine outside my machine. From my machine I can reach this server utilizing ping or telnet on server port, it responds. But from inside docker I cannot reach. I've created my docker using docker-compose an set the network to type bridge.
networks:
app_network_bridge:
driver: bridge
How can I reach from docker an outside server? I've checked with ping and telnet and is not reachable.

How to connect to postgresql instance in with Docker Toolbox with pgadmin4 client

i'm new to Docker, and i'm running it with Docker Toolbox cause i have win 10 family.
I have a training project where there is a database to put up with docker-compose.
Here is the docker-compose.yml (it's given to me, but i can modify it).
version: '2'
services:
myerp.db:
image: postgres:9.4
ports:
- "127.0.0.1:9032:5432"
volumes:
# - "./data/db:/var/lib/postgresql/data"
- "./init/db/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d"
environment:
- POSTGRES_DB=db_myerp
- POSTGRES_USER=usr_myerp
- POSTGRES_PASSWORD=myerp
When i run that through Docker with docker-compose up it seems ok,
but i'm unable to connect to it through a server in pgadmin4
I'm not sure of the connexion setup i'm suppose to put because of Docker ToolBox, where in general to access the running instance you don't use 127.0.0.1 but 192.168.99.100 by defaut.
Anyway, if i configure a postgresql server with
Hostname: 127.0.0.1
Port: 9032
Username and password as written up, i have
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 9032?
If i change the IP in docker-compose for 192.168.99.100, i manage to connect,
but the database is not initialized although there are sql files in the folder
\init\db\docker-entrypoint-initdb.d :
01_create_schema.sql
02_create_tables.sql
21_insert__data_demo.sql
So is it my connexion that is wrongly setup ?
Or should i do it with 192.168.99.100, and it's the initialisation setup that is wrong in the docker-compose ?
Thanks for help !
Ok so i solve the problem, but unfortunately without Docker Toolbox.
I bought a key for windows 10 pro (6€), upgraded the system really fast, and installed Docker Desktop.
Everything worked instantly.
Before the connexion ip was indeed 192.168.99.100, but i don't know why the sql scripts where not copied in the virtual environment, and the folder
/docker-entrypoint-initdb.d
remained empty.
So my solution was to upgrade the system, and everything is fine !

Docker container, running PostgreSQL not allowing php's pg_connect from another container

I have the following architecture:
A network with 3 containers:
container_db, running PostgreSQL
container_pg_admin, running a simple pgAdmin environment
container_php_dev, running the whole environment, needed for the application to function properly (nginx, php, angular for the frontend, etc.)
When I try to pg_connect() from container_php_dev to container_db the connection gets refused. This is the actual error message I get: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: No route to host↵ Is the server running on host "container_db" (172.18.0.4) and accepting↵ TCP/IP connections on port 5432?.
However, when I try to connect to container_db from container_pg_admin I face no problem achieving this (host is container_db and port is 5432). Even if I map port 5432 of container_db to 5555 on host, I'm able to connect to 127.0.0.1:5555 from DBeaver or other DB Manager (TeamSQL).
All containers were restarted a few times as well as docker itself. And as this is my development machine, the host PC was restarted as well.
What might be the problem, how to diagnose and possibly solve? Have any of you experienced such strange docker behaviour?
Try running the container_db in the hosted network using flag --network host

Cannot connect to docker0 (MongoDB chart)

I am completely new to docker. I followed this instruction to install mongodb chart and docker.
When I connect to 172.17.0.1, it said
Unable to connect to MongoDB using the specified URI.
The following error was returned while attempting to connect:
MongoNetworkError: failed to connect to server [172.17.0.1:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 172.17.0.1:27017]
The result from pinging the specified server "172.17.0.1" from within the container is:
PING 172.17.0.1 (172.17.0.1) 56(84) bytes of data.
64 bytes from 172.17.0.1: icmp_seq=1 ttl=64 time=0.050 ms
--- 172.17.0.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.050/0.050/0.050/0.000 ms
The mongodb is running on local machine. I think it is not running in the container (not sure) because I installed mongodb in my machine before I install docker.
I have also checked the setting by using docker network inspect bridge
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
}
]
This is the yml file:
version: "3.3"
services:
charts:
image: quay.io/mongodb/charts:v0.10.0
hostname: charts
ports:
# host:container port mapping. If you want MongoDB Charts to be
# reachable on a different port on the docker host, change this
# to <port>:80, e.g. 8888:80.
- 80:80
- 443:443
volumes:
- keys:/mongodb-charts/volumes/keys
- logs:/mongodb-charts/volumes/logs
- db-certs:/mongodb-charts/volumes/db-certs
- web-certs:/mongodb-charts/volumes/web-certs
environment:
# The presence of following 2 environment variables will enable HTTPS on Charts server.
# All HTTP requests will be redirected to HTTPS as well.
# To enable HTTPS, upload your certificate and key file to the web-certs volume,
# uncomment the following lines and replace with the names of your certificate and key file.
# CHARTS_HTTPS_CERTIFICATE_FILE: charts-https.crt
# CHARTS_HTTPS_CERTIFICATE_KEY_FILE: charts-https.key
# This environment variable controls the built-in support widget and
# metrics collection in MongoDB Charts. To disable both, set the value
# to "off". The default is "on".
CHARTS_SUPPORT_WIDGET_AND_METRICS: "on"
# Directory where you can upload SSL certificates (.pem format) which
# should be considered trusted self-signed or root certificates when
# Charts is accessing MongoDB servers with ?ssl=true
SSL_CERT_DIR: /mongodb-charts/volumes/db-certs
networks:
- backend
secrets:
- charts-mongodb-uri
networks:
backend:
volumes:
keys:
logs:
db-certs:
web-certs:
secrets:
charts-mongodb-uri:
external: true
How can I connect to the mongodb?
By default mongodb is configured to only accept results from localhost 127.0.0.1 and when charts image connects to it via docker it is seen as an external connection coming from docker0 and it is hence rejected by mongod [MongoNetworkError: connect ECONNREFUSED 172.17.0.1:27017]
To fix this, edit the mongo config sudo vim /etc/mongod.conf and add your docker0 ip to the bindIp config the line with bindIp: 127.0.0.1 should be changed to bindIp: 127.0.0.1,172.17.0.1 for default docker installations.
This may be an old question but I think it could be a common issue, I had to struggle with this for a while before actually reading the error message more thoroughly and realising it really a simple issue.
Another issue is that the upon first install you can connect to mongo without a username or password, so those two should be deleted from the uri if you had not configured security, making it mongodb://172.17.0.1:27017.
Assuming you know how to use echo "mongodb://<username>:<password>#myhost.com/" | docker secret create charts-mongodb-uri - to create the connection the url.
The problem is actually how to connect from a docker container to a outside service running on the host machine. You can use some help from plenty of questions like From inside of a Docker container, how do I connect to the localhost of the machine?
Basically, if you are using docker for mac or windows, use something like echo "mongodb://host.docker.internal" | docker secret create charts-mongodb-uri -, for linux see https://docs.mongodb.com/charts/master/installation/ section RUNNING METADATA DATABASE ON LOCALHOST for the doc, or just use host mode (remove ports section)
version: "3.3"
services:
charts:
image: quay.io/mongodb/charts:v0.10.0
hostname: charts
network_mode: "host"
...

google cloud tomcat stack mysql access

I created a tomcat stack instance on google cloud and it comes with mysql 5.5. I can access it through terminal by ssh then enter command line mysql -u username -p. However, I am trying to access the database through mysqlworkbench but I could not get the connection.
So, I guess I need to use connection method "Standard TCP/IP over SSH" and I need to confirm if I have the parameters right.
SSH Hostname: the IP of my instances <br/>
SSH Username: my google account username? this is the one i use to login when setting up the gcloud ssh<br/>
SSH Password: the password for the account<br/>
SSH Key file: ~/.ssh/google_compute_engine<br/>
MySQL Hostname: i put tomcat_rmre which is the hostname for the database when I do "show variables" in the terminal<br/>
MySQL Server Port: the port in "Show variables"<br/>
Username: username of the database<br/>
password: password of the database
When I test connection, I get Lost connection to MySQL server at 'reading initial communication packet', system error: 0
The Tomcat Click to Deploy solution does not use Cloud SQL, it just includes MySQL running on Google Compute Engine.
If you are not able to connect to the MySQL instance remotely via the "Standard (TCP/IP)" connection method it is probably because of one of:
You may have forgotten to open TCP port 3306 in your GCE firewall.
MySQL may not be listening to remote connections. Your my.cnf should contain bind-address = 0.0.0.0 and should not have skip-networking.