Last active
March 24, 2022 15:53
-
-
Save shelajev/85247167d4e0ef36cc85ab6cb63108e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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