Skip to content

Commit 80586af

Browse files
committed
Fix Postgres not being reachable from outside container
1 parent b82e37b commit 80586af

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ COPY postgresql.custom.conf.tmpl /etc/postgresql/10/main/
143143
RUN chown -R postgres:postgres /var/lib/postgresql \
144144
&& chown postgres:postgres /etc/postgresql/10/main/postgresql.custom.conf.tmpl \
145145
&& echo "\ninclude 'postgresql.custom.conf'" >> /etc/postgresql/10/main/postgresql.conf
146+
RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/10/main/pg_hba.conf \
147+
&& echo "host all all ::/0 md5" >> /etc/postgresql/10/main/pg_hba.conf
146148

147149
# copy update scripts
148150
COPY openstreetmap-tiles-update-expire /usr/bin/

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,37 @@ docker run \
9292
run
9393
```
9494

95+
### Connecting to Postgres
96+
97+
To connect to the PostgreSQL database inside the container, make sure to expose port 5432:
98+
99+
```
100+
docker run \
101+
-p 80:80 \
102+
-p 5432:5432 \
103+
-v openstreetmap-data:/var/lib/postgresql/10/main \
104+
-d overv/openstreetmap-tile-server \
105+
run
106+
```
107+
108+
Use the user `renderer` and the database `gis` to connect.
109+
110+
```
111+
psql -h localhost -U renderer gis
112+
```
113+
114+
The default password is `renderer`, but it can be changed using the `PGPASSWORD` environment variable:
115+
116+
```
117+
docker run \
118+
-p 80:80 \
119+
-p 5432:5432 \
120+
-e PGPASSWORD=secret \
121+
-v openstreetmap-data:/var/lib/postgresql/10/main \
122+
-d overv/openstreetmap-tile-server \
123+
run
124+
```
125+
95126
## Performance tuning and tweaking
96127

97128
Details for update procedure and invoked scripts can be found here [link](https://ircama.github.io/osm-carto-tutorials/updating-data/).

postgresql.custom.conf.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ random_page_cost = 1.1
2121
track_activity_query_size = 16384
2222
autovacuum_vacuum_scale_factor = 0.05
2323
autovacuum_analyze_scale_factor = 0.02
24+
25+
listen_addresses = '*'

run.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
set -x
44

5-
function CreatePostgressqlConfig()
6-
{
5+
function createPostgresConfig() {
76
cp /etc/postgresql/10/main/postgresql.custom.conf.tmpl /etc/postgresql/10/main/postgresql.custom.conf
87
sudo -u postgres echo "autovacuum = $AUTOVACUUM" >> /etc/postgresql/10/main/postgresql.custom.conf
98
cat /etc/postgresql/10/main/postgresql.custom.conf
109
}
1110

11+
function setPostgresPassword() {
12+
sudo -u postgres psql -c "ALTER USER renderer PASSWORD '${PGPASSWORD:-renderer}'"
13+
}
14+
1215
if [ "$#" -ne 1 ]; then
1316
echo "usage: <import|run>"
1417
echo "commands:"
@@ -22,14 +25,15 @@ fi
2225

2326
if [ "$1" = "import" ]; then
2427
# Initialize PostgreSQL
25-
CreatePostgressqlConfig
28+
createPostgresConfig
2629
service postgresql start
2730
sudo -u postgres createuser renderer
2831
sudo -u postgres createdb -E UTF8 -O renderer gis
2932
sudo -u postgres psql -d gis -c "CREATE EXTENSION postgis;"
3033
sudo -u postgres psql -d gis -c "CREATE EXTENSION hstore;"
3134
sudo -u postgres psql -d gis -c "ALTER TABLE geometry_columns OWNER TO renderer;"
3235
sudo -u postgres psql -d gis -c "ALTER TABLE spatial_ref_sys OWNER TO renderer;"
36+
setPostgresPassword
3337

3438
# Download Luxembourg as sample if no data is provided
3539
if [ ! -f /data.osm.pbf ]; then
@@ -75,9 +79,10 @@ if [ "$1" = "run" ]; then
7579
fi
7680

7781
# Initialize PostgreSQL and Apache
78-
CreatePostgressqlConfig
82+
createPostgresConfig
7983
service postgresql start
8084
service apache2 restart
85+
setPostgresPassword
8186

8287
# Configure renderd threads
8388
sed -i -E "s/num_threads=[0-9]+/num_threads=${THREADS:-4}/g" /usr/local/etc/renderd.conf

0 commit comments

Comments
 (0)