Get the App
SLTechnology News&Howtos  ›  Development  › 

How to deploy docker to access postgres database

Shulou Source: shulou.com Published: 2022-06-01 04:43:36 09月11日 Update

This article mainly explains "how to deploy docker to access postgres database". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to deploy docker to access postgres database".

Deployment and access

The host creates a postgres user:

Adduser postgres

Pull the image, which is in version 12.1 as an example:

Docker pull postgres:12.1

Create the volume used

Docker volume create pgdata_test_env

Boot (password 123456):

Docker run-- user=0-p 45565 name pg_test 5432-- name pg_test-- restart always\-v pgdata_test_env:/var/lib/postgresql/data\-e POSTGRES_PASSWORD=123456\ postgres:12.1

Access pg and enter the container (note that you need to use postgres users):

Docker exec-ti-u postgres pg_test bashpsql enable logging

Show log_destination; views the logging type and displays off when it is not turned on

Show log_directory; View Log path

Enable logging: alter system set logging_collector='on'; restarts the pg container.

If you need to modify the pg configuration

First look at the docker root address:

Execute docker info, find Docker Root

Docker Root Dir: / opt/docker

Enter inside the volume:

Cd / opt/docker/volumes/pgdata_test_env/_datapostgresql.conf is the configuration file. Restart pg after modification and restart pg.

There are two ways to restart:

Method 1:docker restart pg_test method 2: enter the container, docker exec-ti-u postgres pg_test bashcd / var/lib/postgresql/datapg_ctl restart can restart the successful code & pay attention to external connections (warm reminder)

Both forms of access are available:

1. Use container Ip and mapped intra-container ports

2. Use host ip and mapped host port

If you use the second method, if the following two similar errors do not connect to the pg:

Read: connection reset by peer or

I/o timeout

However, it is normal to use pg to enter the container, so you need to troubleshoot the problems at the network level, such as whether the port is open. If you have any outstanding questions in this regard, you can raise them, and I will help you solve them.

Thank you for reading, the above is the content of "how to deploy docker to access postgres database". After the study of this article, I believe you have a deeper understanding of how to deploy docker to access postgres database, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Container data database log host host port question learning content that is method user configuration success warmth code address password level Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology OPPO Reno Shulou Tech Info Apple Docker