Cuba requires three things:
- The IDE/IntelliJ/CLI
- A modern browser (Firefox/Chrome/etc)
- A DBMS (like PostgreSQL)
This little guide will help set up Postgresql inside a Docker Container and have CUBA connect to it.
Prerequisites
Docker needs to be installed (at time of writing this version: 18.09.3
)
Get postgres
image
docker pull postgres
Run postgres container
After pulling postgres
image successfully, run it into a container while replacing yoursecretpassword
with whatever password you want to set for postgres
. This will also create port forwarding from the host port 5432
to the container port 5432
as 5432:5432
.
Note: if you have a different local postgresql instance running on the same port for some reason, you can opt to change the host port to something else like 5555:5432
docker run --name cuba-postgres -e POSTGRES_PASSWORD=yoursecretpassword -d -p 5432:5432 postgres
Get Docker IP
The network between the container and the host are “bridged”. There are a few ways to get the IP address of the docker host and container.
For Windows
ipconfig
should show the docker network connection. Else docker-machine ip
(for Docker Toolbox) or docker network inspect bridge
in the command prompt should show it as well.
For Linux/Mac
ifconfig
should show the docker network connection. Else docker network inspect bridge
works too.
Test Database and Connection
SSH into the postgres container:
docker exec -it cuba-postgres bash
Open the PSQL shell: psql -U postgres
Create a Database : postgres=# CREATE DATABASE cuba;
Then exit out of the database \q
and container exit
back to host.
For Windows
Lots of apps out there like HeidiSQL and pgAdmin. Just enter all of the details we gathered here and into there where:
- host is the docker IP address
- port is
5432
- user is
postgres
- password is
yoursecretpassword
where you set earlier
For Linux/Mac
If you have a psql
client installed, run psql -d cuba -h <your docker ip xxx.xxx.xx.xxx> -U postgres
Enter password prompt and it works.
Since it works, use the same details for connecting from CUBA to your PostgreSQL.
All the best!