英文:
What are some of the docker container settings for running a single instance of ArangoDB?
问题
我对ArangoDB还不太熟悉,但我可以帮你翻译一下你的问题。你想要在执行GO代码时为ArangoDB创建一个Docker容器,但是有一个限制条件,就是用于创建容器的模块(testcontainers)需要一些参数来设置Docker容器的环境,可能是为了最优化资源利用(例如,在创建Elasticsearch容器时,可以使用"ES_JAVA_OPTS"参数设置JVM的内存为1GB)。
请告诉我这些环境设置对于一个ArangoDB的Docker容器(可能是独立镜像而不是集群镜像)应该是什么,以及如何在运行时进行最优化的设置以实现容器的创建。
英文:
I'm quite new to ArangoDB and I have a requirement to spin off a docker container for ArangoDB, while executing a GO code. The limitation is that the module that enables the spin-off (testcontainers) takes in some parameters for the env settings of the docker container, maybe for the optimal utilisation of resources (For Ex. 1gb for JVM in the case of "ES_JAVA_OPTS" to spin off an Elasticsearch container).
Please let me know what these env settings could be for an Arango docker container (possibly standalone image instead of a cluster one), and how to go about setting them optimally for the spin off to actually happen at run time.
答案1
得分: 1
我能够使用testcontainers-go来重现您的用例。在这里,您可以找到一个片段,用于在测试旁以编程方式引导运行时依赖项,我认为这比将其外部化为对docker-compose的调用更接近开发人员,可能在Makefile或类似的地方调用。
您需要将自己的应用程序容器添加到游戏中
package arangodb
import (
"context"
"testing"
"github.com/docker/docker/api/types/container"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
)
func TestArangoDB(t *testing.T) {
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: 2048 * 1024 * 1024, // 2048 MB
},
WaitingFor: wait.ForLog("is ready for business"),
Mounts: testcontainers.ContainerMounts{
testcontainers.BindMount("/my/database/copy/for/arango/data", "/var/lib/arangodb3"),
},
},
Started: true,
})
require.NoError(t, err)
defer arangodb.Terminate(ctx)
redis, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "redis:alpine",
Networks: []string{networkName},
},
Started: true,
})
require.NoError(t, err)
defer redis.Terminate(ctx)
}
英文:
I was able to reproduce your use case using testcontainers-go. Here you have an snippet bootstrapping the runtime dependencies for your app programatically next to the tests, which imho is closer to the developer than externalizing it to a call to docker-compose, possibly called in a Makefile or similar.
You would need to add your own app container to the game
package arangodb
import (
"context"
"testing"
"github.com/docker/docker/api/types/container"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
)
func TestArangoDB(t *testing.T) {
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: 2048 * 1024 * 1024, // 2048 MB
},
WaitingFor: wait.ForLog("is ready for business"),
Mounts: testcontainers.ContainerMounts{
testcontainers.BindMount("/my/database/copy/for/arango/data", "/var/lib/arangodb3"),
},
},
Started: true,
})
require.NoError(t, err)
defer arangodb.Terminate(ctx)
redis, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "redis:alpine",
Networks: []string{networkName},
},
Started: true,
})
require.NoError(t, err)
defer redis.Terminate(ctx)
}
答案2
得分: 0
我建议使用Docker Compose,并为运行Arango和运行GO代码设置不同的容器。这样,您可以为每个容器设置不同的环境设置。下面是一个示例的docker-compose.yml文件,其中包含Arango、GO和Redis。我添加了Redis,以向您展示如果需要,您还可以添加更多的服务。
version: '3.9'
# 定义服务
services:
arangodb:
image: arangodb/arangodb:latest
ports:
- 8529:8529
volumes:
- /my/database/copy/for/arango/data:/var/lib/arangodb3
environment:
- ARANGODB_USERNAME=myuser
- ARANGODB_PASSWORD=mypassword
- ARANGODB_DBNAME=graphdb
- ARANGO_ROOT_PASSWORD=myrootpassword
container_name: "arango_docker_compose"
mem_limit: 2048m
networks:
- backend
# Golang Service
app:
# 基于您选择的Dockerfile构建服务的Docker镜像
build:
context: . # 使用当前目录中指定的Dockerfile构建镜像。
dockerfile: Dockerfile
ports:
- "8080:8080" # 将容器上暴露的端口8080转发到主机上的端口8080,如果需要的话
restart: unless-stopped
depends_on:
- redis # 此服务依赖于redis和arangodb。先启动它们。
- arangodb
environment: # 将环境变量传递给服务
- REDIS_URL: redis:6379
- ARANGO_PORT: 8529
networks: # 加入的网络(在同一网络上的服务可以使用它们的名称相互通信)
- backend
# Redis Service
redis:
image: "redis:alpine" # 使用公共Redis镜像构建redis服务
restart: unless-stopped
networks:
- backend
networks:
backend:
有关允许在ArangoDB Docker镜像上使用的参数的更多信息,请参见ArangoDB Docker Hub。
GO容器的示例Dockerfile可以在这里找到。请注意,这些文件只是示例,您需要根据需要添加/替换所需的配置。由于您想使用testcontainers
,您还可以使用这里的Dockerfile。
请告诉我这是否有帮助。
谢谢!
英文:
I would suggest to use docker compose and setup different containers for running Arango and another one for running the GO code. That way you can have different env settings for each of them. Below you can see a sample docker-compose.yml file that has Arano, GO and redis. I am adding Redis to show you that you can add even more services there if needed
version: '3.9'
# Define services
services:
arangodb:
image: arangodb/arangodb:latest
ports:
- 8529:8529
volumes:
- /my/database/copy/for/arango/data:/var/lib/arangodb3
environment:
- ARANGODB_USERNAME=myuser
- ARANGODB_PASSWORD=mypassword
- ARANGODB_DBNAME=graphdb
- ARANGO_ROOT_PASSWORD=myrootpassword
container_name: "arango_docker_compose"
mem_limit: 2048m
networks:
- backend
# Golang Service
app:
# Building the docker image for the service based on a Dockerfile of your choice
build:
context: . # Use an image built from the specified dockerfile in the current directory.
dockerfile: Dockerfile
ports:
- "8080:8080" # Forward the exposed port 8080 on the container to port 8080 on the host machine, if needed
restart: unless-stopped
depends_on:
- redis # This service depends on redis and arangodb. Start them first.
- arangodb
environment: # Pass environment variables to the service
- REDIS_URL: redis:6379
- ARANGO_PORT: 8529
networks: # Networks to join (Services on the same network can communicate with each other using their name)
- backend
# Redis Service
redis:
image: "redis:alpine" # Use a public Redis image to build the redis service
restart: unless-stopped
networks:
- backend
networks:
backend:
For more information about the parameters allowed on ArangoDB docker image please see ArangoDB docker hub
A sample Dockerfile for GO container can be found at here. Please bare in mind that these files are mere samples and you will need to add/replace your required configuration on them. As you want to use testcontainers
you can also use the Dockerfile here
Please let me know whether that helps
Thank you!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论