docker - 在Gitlab CI中使用Docker镜像时,如何引用服务的别名

标签 docker gitlab alias

以下是我的gitlab-ci.yml文件的摘录。简而言之,我需要创建一个redis服务,然后根据测试需要引用它。

因为redis服务器是动态创建的,所以我不知道一种简单的方法告诉它查看'localhost'或123.321.234.234等。

有没有一种方法可以引用服务的别名(例如下面创建的服务),以便可以将其值传递到另一个容器中,以便它们“对话”?在我的代码中,我试图引用'redis'别名,并在管道过程中将该值提供给环境变量,但是它变成了文字字符串。

我也尝试了$ {redis},但同样失败。

我得到的最深入的内容是我从有关 anchor 的gitlab文档中读到的内容,下面是我的内容。

以下是我寻找答案的地方

https://docs.gitlab.com/ce/ci/yaml/README.html
https://docs.gitlab.com/ee/ci/docker/using_docker_images.html

# the image and gitlab services to use in the build stages
.build-web-image: &build-web-image
 image: Dontworryaboutit.com:4567/folder/dockerImage:1.0.0
 services:
  - name: redis:3.2.8
    alias: redis

# The job that runs the yarn run test that requires a redis server
Test Web:
 <<: *build-web-image
 stage: Stage 2
 before_script:
  - export REDIS=redis:1234
  - yarn
 script:
  - yarn run test

最佳答案

可以通过引用别名来取消引用别名,而无需使用其他修饰

${variable}

您可以输入
 variable

确保检查您的config.toml文件,以确保将docker executor用于该运行程序。切换CI / CD策略时很容易犯一个错误。

关于docker - 在Gitlab CI中使用Docker镜像时,如何引用服务的别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50282245/

相关文章:

node.js - 如何使用 Docker Compose 将容器 A 中的 Node.js TCP 客户端连接到容器 B 中的 TCP 服务器?

Gitlab Omnibus - 安装问题 - CentOS 7 (SELinux)

scala - scala中的类别名

ssl - 无法停止Gitlab内置的Nginx

php - 获取连接表的列名

sql - SQL Server 中的别名列名

angular - "[NetworkError]"在 Angular SSR 控制台中,没有附加信息

java - 如何使用 Testcontainers 将可执行文件复制到 Docker 容器

java - 智能 : use docker jvm or docker maven?

python - 为什么我的 Gitlab 请求总是返回错误 400