- Docker Postgresql Database
- Install Postgres Docker-compose
- Using Postgresql Docker Image
- Install Postgresql Docker Mac
I use PostgreSQL on one of my projects (honestly I’d like to use it almost everywhere) and will show you how to install and use it with Docker. Actually, on my daily job, I have Mongo, Postgres and Redis as databases and it makes it really convenient to use them together with the Docker. Install PostgreSQL on macOS; Install PostgreSQL on Linux; PostgreSQL was developed for UNIX-like platforms, however, it was designed to be portable. It means that PostgreSQL can also run on other platforms such as macOS, Solaris, and Windows. Since version 8.0, PostgreSQL offers an installer for Windows systems that makes the installation. The driver should be installed. Now, type in the Docker host IP address 192.168.20.160 (in my case) as the Host, 5432 as the Port, admin as the User, secret as the Password, postgres as the Database and click on Test Connection. You should see the PostgreSQL database server details if everything works.
Prerequisites
- Docker
- Docker Compose (Optional)
If you didn’t install them already look at these links:
Install wget in mac. You can check them via:
Build Container
Execute below command to create a PostgreSQL container:
This command will download Postgres 11.6 from Docker Postgre Hub.
If we look in detail:
-d
: means run in detached mode,--name
: we give container a name : localpostgres,-e
: environment variable;postgres:11.6
: is our main image that we create the container upon
Docker Postgresql Database
Info
I use PostgreSQL version 11.6 since I have it already but you can usewhatever version you want.
Also if you leave tagblank docker will fetch the latest version.
However I definitely don’t recommend that since it may break your software stack. Getting started with docker on mac os.
Get Into the Container
After creating the container we can access it on our host:
Use the Container
Create a Database Legends of runeterra mac download.
We will create a database inside our PostgreSQL container:
Create a Table
Let’s create an example table inside our testdb:
Install Postgres Docker-compose
Check Table/Relations
To check your table:
Use Docker Compose
Instead of raw docker command we can use docker compose to create and accessto our PostgreSQL database.
Create a file named docker-compose.yml
with below code:
Spin up our container:
This command builds, (re)creates, starts, and attaches to containers for a service.
Now we can directly connect the database -testdb
, with the user -debug
:
All done!
Using Postgresql Docker Image
Changelog
Install Postgresql Docker Mac
- 2021-03-03 : Add missing
-
fordocker exec
command