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

How to create an index on a join table in MySQL

This article introduces how to create an index on...

Use js to write a simple snake game

This article shares the specific code of a simple...

Detailed installation tutorial of mysql-8.0.11-winx64.zip

Download the zip installation package: Download a...

Linux cut command explained

The cut command in Linux and Unix is ​​used to cu...

Front-end advanced teaching you to use javascript storage function

Table of contents Preface Background Implementati...

Steps for Vue3 to use mitt for component communication

Table of contents 1. Installation 2. Import into ...

Detailed troubleshooting of docker.service startup errors

Execute the following command to report an error ...

Comparative Analysis of IN and Exists in MySQL Statements

Background Recently, when writing SQL statements,...

Detailed explanation of MySQL transaction processing usage and example code

MySQL transaction support is not bound to the MyS...

v-for directive in vue completes list rendering

Table of contents 1. List traversal 2. The role o...

Native JavaScript to achieve the effect of carousel

This article shares the specific code for JavaScr...

Detailed tutorial on installing nvidia driver + CUDA + cuDNN in Ubuntu 16.04

Preparation 1. Check whether the GPU supports CUD...

Vue3 (Part 2) Integrating Ant Design Vue

Table of contents 1. Integrate Ant Design Vue 2. ...

The use of v-model in vue3 components and in-depth explanation

Table of contents Use two-way binding data in v-m...