Reputation: 73
I'm trying to use https://golang.testcontainers.org to setup a docker container from the image that I specify, while the code is in execution. The container spun out, will be cleaned up before the program terminates, as mentioned in the above link.
This is the code I have to setup an "arangoContainerRequest" :
arangoContainerRequest := testcontainers.ContainerRequest{
Image: "arangodb/arangodb:3.7.5",
Name: "arango",
ExposedPorts: []string{"8529/tcp"},
Env: map[string]string{
// what config details to specify?
},
WaitingFor: wait.ForLog("Waiting for connections").WithStartupTimeout(time.Minute * 15),
}
This is the code I have to start the container up and defer its termination :
arangoContainer, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: arangoContainerRequest,
Started: true,
})
defer arangoContainer.Terminate(ctx)
With these in place, I'm getting a timeout message saying "context deadline exceeded", where the container times out without even being created.
Maybe for some config value for the "Env" field in the "arangoContainerRequest" map, the container can be spun out dynamically (so that maybe the container isn't too bulky), but I'm unable to figure out the same.
Any form of help would be highly appreciated.
Upvotes: 3
Views: 295
Reputation: 111
I'd consider checking out the official docs for ArangoDB, i.e. the Docker Hub page for it: https://hub.docker.com/_/arangodb
I think this code snippet will help you out in setting up the container, as it works for me.
ctx := context.Background()
networkName := "backend"
newNetwork, err := testcontainers.GenericNetwork(ctx, testcontainers.GenericNetworkRequest{
NetworkRequest: testcontainers.NetworkRequest{
Name: networkName,
CheckDuplicate: true,
},
})
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
require.NoError(t, newNetwork.Remove(ctx))
})
arangodb, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "arangodb/arangodb:latest",
Env: map[string]string{
"ARANGODB_USERNAME": "myuser",
"ARANGODB_PASSWORD": "mypassword",
"ARANGODB_DBNAME": "graphdb",
"ARANGO_ROOT_PASSWORD": "myrootpassword",
},
Networks: []string{networkName},
Resources: container.Resources{
Memory: 256 * 1024 * 1024, // 512 MB
},
WaitingFor: wait.ForLog("is ready for business").WithStartupTimeout(time.Minute * 1),
},
Started: true,
})
require.NoError(t, err)
defer arangodb.Terminate(ctx)
Upvotes: 0