First create a .env file with the following structure (names are like this because i'm using postgres)
POSTGRES_CONTAINER_NAME=
POSTGRES_CONTAINER_IMAGE_NAME=
postgres_USER=
postgres_PASS=
postgres_DB=
postgres_PORT=
- POSTGRES_CONTAINER_NAME // ContainerName
- POSTGRES_CONTAINER_IMAGE_NAME // Image name you can get it from the Docker Hub -> https://hub.docker.com/_/postgres/
- postgres_USER // User usually postgres for working locally
- postgres_PASS // Password usually postgress too
- postgres_DB // For working locally postgres uses to be a standard name too
- postgres_PORT // 5433 Default
version: "3.8"
services:
postgres:
container_name: ${POSTGRES_CONTAINER_NAME}
image: ${POSTGRES_CONTAINER_IMAGE_NAME}
restart: "no"
env_file:
- .env
environment:
- POSTGRES_PASSWORD=${postgres_PASS}
- POSTGRES_USER=${postgres_USER}
- POSTGRES_DB=${postgres_DB}
ports:
- ${postgres_PORT}:5432
volumes:
- ./data_postgres:/var/lib/postgresql/data
once we have ready our docker-compose.yml we run the following command
_ docker compose up -d
to check if we have our container running we can check it with the following command
docker ps
now for connecting to our db in DBeaver we are going to need the ip for the container to do that copy the container id from there and run the next command
docker inspect <Container-ID>
at the end of the response we get the following structure
"Networks": {
"vehiclesretail_default": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"string",
"string",
"string"
],
"NetworkID": "string",
"EndpointID": "string",
"Gateway": "string",
"IPAddress": "string" // This is the line we need
"IPPrefixLen": "number",
"IPv6Gateway": "string",
"GlobalIPv6Address": "string",
"GlobalIPv6PrefixLen": "number",
"MacAddress": "string",
"DriverOpts": null
}
}
now we are going to open DBeaver and create a new connection
- Database
- New Database Collection
populate the fields required and click on test connection
if everything is okay we should see the following image
after that click finish and here we go! we have our DBeaver connected to our docker container.
thanks