Skip to content

Commit 245c8f3

Browse files
authored
Merge pull request dockersamples#159 from shipyardbuild/fix-postgres-init
Set an explicit username and password for the db service
2 parents 2209b3a + e8e002b commit 245c8f3

12 files changed

+36
-6
lines changed

docker-compose-javaworker.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ services:
4141
db:
4242
image: postgres:9.4
4343
container_name: db
44+
environment:
45+
POSTGRES_USER: "postgres"
46+
POSTGRES_PASSWORD: "postgres"
4447
volumes:
4548
- "db-data:/var/lib/postgresql/data"
4649
networks:

docker-compose-k8s.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ services:
77
- "6379:6379"
88
db:
99
image: postgres:9.4
10+
environment:
11+
POSTGRES_USER: "postgres"
12+
POSTGRES_PASSWORD: "postgres"
1013
ports:
1114
- "5432:5432"
1215
vote:

docker-compose-simple.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ services:
1818

1919
db:
2020
image: postgres:9.4
21+
environment:
22+
POSTGRES_USER: "postgres"
23+
POSTGRES_PASSWORD: "postgres"
2124

2225
result:
2326
build: ./result

docker-compose.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ services:
4343
db:
4444
image: postgres:9.4
4545
container_name: db
46+
environment:
47+
POSTGRES_USER: "postgres"
48+
POSTGRES_PASSWORD: "postgres"
4649
volumes:
4750
- "db-data:/var/lib/postgresql/data"
4851
networks:
@@ -53,4 +56,4 @@ volumes:
5356

5457
networks:
5558
front-tier:
56-
back-tier:
59+
back-tier:

docker-stack-simple.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ services:
1616
condition: on-failure
1717
db:
1818
image: postgres:9.4
19+
environment:
20+
POSTGRES_USER: "postgres"
21+
POSTGRES_PASSWORD: "postgres"
1922
volumes:
2023
- db-data:/var/lib/postgresql/data
2124
networks:
@@ -78,4 +81,4 @@ networks:
7881
backend:
7982

8083
volumes:
81-
db-data:
84+
db-data:

docker-stack.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ services:
1414
condition: on-failure
1515
db:
1616
image: postgres:9.4
17+
environment:
18+
POSTGRES_USER: "postgres"
19+
POSTGRES_PASSWORD: "postgres"
1720
volumes:
1821
- db-data:/var/lib/postgresql/data
1922
networks:

k8s-specifications/db-deployment.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ spec:
1818
containers:
1919
- image: postgres:9.4
2020
name: postgres
21+
env:
22+
- name: POSTGRES_USER
23+
value: postgres
24+
- name: POSTGRES_PASSWORD
25+
value: postgres
2126
ports:
2227
- containerPort: 5432
2328
name: postgres

kube-deployment.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ spec:
7777
env:
7878
- name: PGDATA
7979
value: /var/lib/postgresql/data/pgdata
80+
- name: POSTGRES_USER
81+
value: postgres
82+
- name: POSTGRES_PASSWORD
83+
value: postgres
8084
ports:
8185
- containerPort: 5432
8286
name: db

result/docker-compose.test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ services:
4747

4848
db:
4949
image: postgres:9.4
50+
environment:
51+
POSTGRES_USER: "postgres"
52+
POSTGRES_PASSWORD: "postgres"
5053
volumes:
5154
- "db-data:/var/lib/postgresql/data"
5255
networks:

result/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ io.sockets.on('connection', function (socket) {
2424
});
2525

2626
var pool = new pg.Pool({
27-
connectionString: 'postgres://postgres@db/postgres'
27+
connectionString: 'postgres://postgres:postgres@db/postgres'
2828
});
2929

3030
async.retry(

worker/src/Worker/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static int Main(string[] args)
1616
{
1717
try
1818
{
19-
var pgsql = OpenDbConnection("Server=db;Username=postgres;");
19+
var pgsql = OpenDbConnection("Server=db;Username=postgres;Password=postgres;");
2020
var redisConn = OpenRedisConnection("redis");
2121
var redis = redisConn.GetDatabase();
2222

@@ -46,7 +46,7 @@ public static int Main(string[] args)
4646
if (!pgsql.State.Equals(System.Data.ConnectionState.Open))
4747
{
4848
Console.WriteLine("Reconnecting DB");
49-
pgsql = OpenDbConnection("Server=db;Username=postgres;");
49+
pgsql = OpenDbConnection("Server=db;Username=postgres;Password=postgres;");
5050
}
5151
else
5252
{ // Normal +1 vote requested

worker/src/main/java/worker/Worker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static Connection connectToDB(String host) throws SQLException {
7272

7373
while (conn == null) {
7474
try {
75-
conn = DriverManager.getConnection(url, "postgres", "");
75+
conn = DriverManager.getConnection(url, "postgres", "postgres");
7676
} catch (SQLException e) {
7777
System.err.println("Waiting for db");
7878
sleep(1000);

0 commit comments

Comments
 (0)