Skip to content

Commit 4f3f58e

Browse files
committed
#13 Adjusted the logic to check whether a container already exists. Now it no longer checks the image name + version, just the container name.
Logged the after-verification-wait property in the boot sequence. Updated the docs.
1 parent c99f072 commit 4f3f58e

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

Diff for: README.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ docker:
9494
image-version: 9.6
9595
force-clean: true
9696
container-name: postgression2
97-
port: 5433
97+
port: 5434
9898
```
9999
100+
Be sure to point your datasource url to the same port.
101+
100102
Note that the force-clean flag is useful for tests. There is no reason to keep the container in that case and you might as well remove it, when another version is found.
101103
102104
Since the Postgres containers will be run on different identifiers and ports, you can run them in parallel.
@@ -159,6 +161,24 @@ When a failure occurs, the error log will be read and logged. If the container s
159161

160162
If the container does not start up, the Spring Boot startup sequence will be terminated.
161163

164+
## Slow system?
165+
166+
If you have a slow system, your Spring Boot may be faster than the time when Postgres is really ready (ie, this is not the same as when Docker tells it is ready). The result is the following error:
167+
168+
```
169+
Caused by: org.postgresql.util.PSQLException: FATAL: the database system is starting up
170+
```
171+
172+
This can be remedied by applying a post startup verification wait time (in milliseconds) to your application:
173+
174+
```yaml
175+
docker:
176+
postgres:
177+
afterVerificationWait: 2000
178+
```
179+
180+
In this example, it will wait for an extra 2 seconds.
181+
162182
# Docker Postgres in action
163183

164184
When docker-postgres starts, your log will show this:

Diff for: src/main/java/nl/_42/boot/docker/postgres/DockerContainerAvailableCheck.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,18 @@ public class DockerContainerAvailableCheck extends AbstractDockerAvailableCheck
1212
private final static String COMMAND = "docker ps";
1313

1414
private final String containerName;
15-
private final String imageNameAndVersion;
1615

1716
public DockerContainerAvailableCheck(DockerPostgresProperties properties) {
1817
super(COMMAND, properties);
1918
this.containerName = properties.getContainerName();
20-
this.imageNameAndVersion = properties.getImageName() + ":" + properties.getImageVersion();
2119
}
2220

2321
public boolean hasContainer() throws IOException {
24-
if (hasValues(new ExpectedValue(1, imageNameAndVersion), new ExpectedValue(6, containerName))) {
25-
LOGGER.info("| Container [" + containerName + " for " + imageNameAndVersion + "] exists");
22+
if (hasValues(new ExpectedValue(6, containerName))) {
23+
LOGGER.info("| Container [" + containerName + "] exists");
2624
return true;
2725
}
28-
LOGGER.info("| Container [" + containerName + " for " + imageNameAndVersion + "] not found; no force remove needed");
26+
LOGGER.info("| Container [" + containerName + "] not found; no force remove needed");
2927
return false;
3028
}
3129

Diff for: src/main/java/nl/_42/boot/docker/postgres/DockerPostgresBootSequence.java

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public DockerPostgresContainer execute() throws IOException, InterruptedExceptio
2626
LOGGER.info("| * Port: " + properties.getPort());
2727
LOGGER.info("| * Password: " + properties.getPassword());
2828
LOGGER.info("| * Startup Verification Text: [" + properties.getStartupVerificationText() + "]");
29+
LOGGER.info("| * After verification wait: " + properties.getAfterVerificationWait() + "ms");
2930
LOGGER.info("| * Docker command: [" + properties.getDockerCommand() + "]");
3031
LOGGER.info("| * Custom variables (" + properties.getCustomVariables().size() + ")");
3132
for (String key : properties.getCustomVariables().keySet()) {

0 commit comments

Comments
 (0)