Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deploy docker to access postgres database

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report