Skip to content

Instantly share code, notes, and snippets.

@shelajev
Last active March 24, 2022 15:53
Show Gist options
  • Save shelajev/85247167d4e0ef36cc85ab6cb63108e2 to your computer and use it in GitHub Desktop.
Save shelajev/85247167d4e0ef36cc85ab6cb63108e2 to your computer and use it in GitHub Desktop.
// Here's the network where both containers will join
static final Network NET = Network.newNetwork();
// The database container will join the network under the 'mysql' alias
@Container
static MySQLContainer dbContainer =
new MySQLContainer<>(DockerImageName.parse("mysql:8.0"))
.withNetwork(NET)
.withNetworkAliases("mysql");
// The Payara Micro container will also join the network and be configured to depend on the database container
@Container
static GenericContainer microContainer =
new GenericContainer(DockerImageName.parse("payara/micro-jdk11"))
.withExposedPorts(8080)
.dependsOn(dbContainer)
.withNetwork(NET)
.withCopyFileToContainer(warFile, "/opt/payara/deployments/app.war")
.waitingFor(Wait.forLogMessage(".* Payara Micro .* ready in .*\\s", 1))
.withEnv("DB_JDBC_URL", String.format("jdbc:mysql://mysql:3306/%s", dbContainer.getDatabaseName()))
.withEnv("DB_USER", dbContainer.getUsername())
.withEnv("DB_PASSWORD", dbContainer.getPassword())
.withCommand("--deploy /opt/payara/deployments/app.war --contextRoot /");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment