在 .gitlab-ci.yml 中运行 docker-compose build [英] Run docker-compose build in .gitlab-ci.yml

查看:20
本文介绍了在 .gitlab-ci.yml 中运行 docker-compose build的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .gitlab-ci.yml 文件,其中包含以下内容:

I have a .gitlab-ci.yml file which contains following:

image: docker:latest

services:
  - docker:dind

before_script:
  - docker info
  - docker-compose --version

buildJob:
  stage: build
  tags:
    - docker
  script:
    - docker-compose build

但是在 ci-log 中我收到消息:

But in ci-log I receive message:

$ docker-compose --version
/bin/sh: eval: line 46: docker-compose: not found

我做错了什么?

推荐答案

EDIT 我添加了另一个答案,为支持 docker-compose 的 .gitlab-ci.yml 配置提供了一个最小示例.

EDIT I added another answer providing a minimal example for a .gitlab-ci.yml configuration supporting docker-compose.

docker-compose 可以作为 Python 包安装,它不随您的映像一起提供.您选择的图像甚至不提供 Python 的安装:

docker-compose can be installed as a Python package, which is not shipped with your image. The image you chose does not even provide an installation of Python:

$ docker run --rm -it docker sh
/ # find / -iname "python"
/ # 

寻找 Python 给出了一个空的结果.所以你必须选择一个不同的图像,它适合你的需要,最好安装 docker-compose 或者你手动创建一个.

Looking for Python gives an empty result. So you have to choose a different image, which fits to your needs and ideally has docker-compose installed or you maually create one.

您选择的 docker 镜像使用的是 Alpine Linux.如果您不熟悉 Alpine Linux,您可以将其用作您自己映像的基础,或者先尝试不同的映像.

The docker image you chose uses Alpine Linux. You can use it as a base for your own image or try a different one first if you are not familiar with Alpine Linux.

我遇到了同样的问题,在公共 GitHub 存储库中创建了一个 Dockerfile,并将其与我的 Docker Hub 帐户连接,并选择了自动构建来在每次推送到 GitHub 存储库时构建我的映像.然后,您可以使用 GitLab CI 轻松访问自己的图像.

I had the same issue and created a Dockerfile in a public GitHub repository and connected it with my Docker Hub account and chose an automated build to build my image on each push to the GitHub repository. Then you can easily access your own images with the GitLab CI.

这篇关于在 .gitlab-ci.yml 中运行 docker-compose build的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆