【问题标题】:What are some of the docker container settings for running a single instance of ArangoDB?运行单个 ArangoDB 实例的 docker 容器设置有哪些?
【发布时间】:2022-11-09 23:51:24
【问题描述】:

我对 ArangoDB 很陌生,我需要在执行 GO 代码时为 ArangoDB 分离一个 docker 容器。限制是启用分拆(testcontainers)的模块为 docker 容器的 env 设置接受一些参数,可能是为了优化资源利用(例如,在“ES_JAVA_OPTS”的情况下,JVM 的 1gb 到剥离一个 Elasticsearch 容器)。

请让我知道这些环境设置对于 Arango docker 容器(可能是独立映像而不是集群容器)可能是什么,以及如何对它们进行最佳设置,以便在运行时实际发生分拆。

【问题讨论】:

  • 您将如何使用 Docker CLI 运行容器?您可以使用 Testcontainers 复制它,

标签: docker go arangodb testcontainers


【解决方案1】:

我建议使用 docker compose 并设置不同的容器来运行 Arango 和另一个容器来运行 GO 代码。这样你就可以为它们中的每一个设置不同的环境设置。下面你可以看到一个示例 docker-compose.yml 文件,其中包含 Arano、GO 和 redis。我添加 Redis 是为了向您展示,如果需要,您可以在那里添加更多服务

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:  

有关 ArangoDB docker 映像上允许的参数的更多信息,请参阅ArangoDB docker hub

可以在here 找到 GO 容器的示例 Dockerfile。请记住,这些文件只是示例,您需要在它们上添加/替换所需的配置。如果你想使用testcontainers,你也可以使用Dockerfile here

请让我知道这是否有帮助

谢谢!

【讨论】:

    【解决方案2】:

    我能够使用testcontainers-go 重现您的用例。在这里,您有一个 sn-p 以编程方式在测试旁边引导您的应用程序的运行时依赖项,恕我直言,与将其外部化为对 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)
    }
    

    【讨论】:

      猜你喜欢
      • 2018-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      相关资源
      最近更新 更多