Examples connecting to PostgreSQL
Create the image, this line tells Docker to build an image from the Dockerfile and give it a name of 'my-postgres-db':`docker build -t my-postgres-db ./`
We got our own image called 'my-postgres-db'. We can run it as a container by doing:
docker run -d --name my-postgresdb-container -p 5432:5432 my-postgres-db
To enter the container:
docker exec -it postgres-docker bash
- exec we’ve entered a postgres-docker image
- -it in detached mode
- bash to run its bash app
You need to use the following connection details to connect to the DB:
- Host: localhost
- Port: 5432
- User: postgres
- Password: docker (from Dockerfile)
- Database name: usershop (from Dockerfile)
To see the images:
docker images -a
To remove images:
docker image rm 'nameOfTheImage'
'database/sql' package from the standard library
To extend its interfaces from the standard library [github.com/jackc/pgx](https://github.com/jackc/pgx)