How to install Postgres 12 + pgadmin in local Docker (support Apple M1)

How to install Postgres 12 + pgadmin in local Docker (support Apple M1)

introduce

The project recently upgraded the Posgres database from 9.6 to 12+. In order to do some migration tests, I need to install several versions of Postgres locally. The most convenient way is to install it using Docker. There is no version conflict problem, and it is easy to manage and delete.

It is also recommended to use docker-compose or stack. Simply put, the data can be stored locally, so that the data will not be lost each time it is restarted and can be reused. If you are doing integration testing, you can start a new DB each time.

The following docker-compose file also contains pgAdmin, which makes it easier to use Postgres. You can also use your favorite DB browser. I use the Database plugin that comes with IDEA (ultimate).

Support Intel CPU

I used it for a while under MacOS and it was fine.

  • Save as docker-compose.yml file
  • Run docker-compose up -d in the file path

illustrate:

  • User and password can be set at will
  • Volumes is the path where the database is saved locally
  • ports: The default is 5432. I usually like to change it to 15432. There are many projects, and the port below 10000 is very crowded.
  • The email and password of pgadmin are the login passwords of the page
  • pgadmin's volumes and ports are the same as Postgres
version: '3.5'

services:
 postgres:
 container_name: pg12
 image: postgres:12
 environment:
 POSTGRES_USER: pg12
 POSTGRES_PASSWORD: pg12
 PGDATA: /data/postgres
 volumes:
 - postgres12:/Users/szhang/postgresql/pg12
 ports:
 - "5432:5432"
 networks:
 - pg12
 restart: unless-stopped

 pgadmin:
 container_name: pgadmin12
 image: dpage/pgadmin4
 environment:
 PGADMIN_DEFAULT_EMAIL: [email protected]
 PGADMIN_DEFAULT_PASSWORD: [email protected]
 volumes:
 - pgadmin12:/Users/szhang/postgresql/.pgadmin12
 ports:
 - "27777:80"
 networks:
 - pg12
 restart: unless-stopped

networks:
 pg12:
 driver: bridge

volumes:
 postgres12:
 pgadmin12:

Support for Apple M1

The only difference in this version is that the Postgres image is an ARM version, which specifically supports computers with the latest Apple M1 chip. One more thing, Apple M1 computers can run Docker, but many Docker images do not have ARM versions yet, so it is not convenient to use M1 computers for development (which requires Docker) at present.

version: '3.5'

services:
 postgres:
 container_name: pg12
 image: arm64v8/postgres:12.6
 environment:
 POSTGRES_USER: pg12
 POSTGRES_PASSWORD: pg12
 PGDATA: /data/postgres
 volumes:
 - postgres12:/Users/shubozhang/dev/postgresql/pg12
 ports:
 - "5432:5432"
 networks:
 - pg12
 restart: unless-stopped

 pgadmin:
 container_name: pgadmin12
 image: dpage/pgadmin4
 environment:
 PGADMIN_DEFAULT_EMAIL: [email protected]
 PGADMIN_DEFAULT_PASSWORD: [email protected]
 volumes:
 - pgadmin12:/Users/shubozhang/dev/postgresql/.pgadmin12
 ports:
 - "27777:80"
 networks:
 - pg12
 restart: unless-stopped

networks:
 pg12:
 driver: bridge

volumes:
 postgres12:
 pgadmin12:

test

pgAdmin

Log in, using the email and password in docker-compose

User Interface

Intellij IDE

Use username, password, and port to connect.

This is the end of this article about installing Postgres 12 + pgadmin (supporting Apple M1) with local Docker. For more relevant content about installing Postgres with Docker, please search previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • About Docker deployment postgresql database
  • Running PostgreSQL in Docker and recommending several connection tools
  • Solution for creating multiple databases when Docker starts PostgreSQL
  • Detailed steps to upgrade PostgreSQL in Docker environment
  • How to install and persist the postgresql database in docker
  • How to run postgreSQL with docker
  • Database backup in docker environment (postgresql, mysql) example code
  • How to deploy docker to access postgres database

<<:  Vue-CLI3.x automatically deploys projects to the server

>>:  Detailed explanation of MySQL binlog usage

Recommend

Solution to the problem of MySQL thread in Opening tables

Problem Description Recently, there was a MySQL5....

21 MySQL standardization and optimization best practices!

Preface Every good habit is a treasure. This arti...

Share JS four fun hacker background effect codes

Table of contents Example 1 Example 2 Example 3 E...

Book page turning effects made with CSS3

Result:Implementation code: html <!-- Please h...

Detailed explanation of using top command to analyze Linux system performance

Introduction to Linux top command The top command...

HTML tutorial, easy to learn HTML language (2)

*******************Introduction to HTML language (...

Summary of Docker common commands and tips

Installation Script Ubuntu / CentOS There seems t...

Implementation of fuzzy query like%% in MySQL

1, %: represents any 0 or more characters. It can...

Implementation of Nginx configuration of multi-port and multi-domain name access

To deploy multiple sites on a server, you need to...

How to change the domestic image source for Docker

Configure the accelerator for the Docker daemon S...

MySQL transaction autocommit automatic commit operation

The default operating mode of MySQL is autocommit...

Summary of web design experience and skills

■ Website theme planning Be careful not to make yo...

Will the index be used in the MySQL query condition?

When an employer asks you whether an index will b...