【问题标题】:creating docker images in two git environments在两个 git 环境中创建 docker 镜像
【发布时间】:2023-04-10 18:33:01
【问题描述】:

我是 docker 新手,我正在尝试建立一个气流 QA 环境(我已经有一个生产环境)。这就是我在 entrypoint.sh 中定义的方式

#!/usr/bin/env bash

TRY_LOOP="20"
SLUGIFY_USES_TEXT_UNIDECODE=yes

BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$BRANCH" == 'master' ]
then
   "${REDIS_HOST:="airflow-celery.xxxxx.0001.use1.cache.amazonaws.com"}"
else [ "$BRANCH" == 'QA' ]
   "${REDIS_HOST:="qa-airflow-celery.xxxx.ng.0001.use1.cache.amazonaws.com"}"
fi

: "${REDIS_PORT:="6379"}"

if [ "$BRANCH" == 'master' ]
then
  "${POSTGRES_HOST:="airflow-database.xxxxx.us-east-1.rds.amazonaws.com"}"
  "${POSTGRES_USER:="airflow"}"
else [ "$BRANCH" == 'QA' ]
  "${POSTGRES_HOST:="qa-airflow-database.xxxxx.us-east-1.rds.amazonaws.com"}"
  "${POSTGRES_USER:="airflow"}"
fi

构建成功运行,但是当我尝试运行 docker 容器时它会引发以下错误并且它永远不会启动

/entrypoint.sh: line 6: git: command not found
/entrypoint.sh: line 11: qa-airflow-celery.xxxxx.ng.0001.use1.cache.amazonaws.com: command not found
/entrypoint.sh: line 21: qa-airflow-database.xxxxxxx.us-east-1.rds.amazonaws.com: command not found

如果我能提供一些帮助,我将不胜感激。

【问题讨论】:

  • 您使用的 Docker 容器的镜像似乎没有安装 Git。你用的是什么图片?
  • @Omer:我正在使用 docker 气流图像

标签: git shell docker github


【解决方案1】:

最后 2 个错误发生是因为 双引号内有双引号

/entrypoint.sh: line 11: qa-airflow-celery.xxxxx.ng.0001.use1.cache.amazonaws.com: command not found
/entrypoint.sh: line 21: qa-airflow-database.xxxxxxx.us-east-1.rds.amazonaws.com: command not found  

我认为你可以去掉所有 bash 文件中的外引号

#!/usr/bin/env bash

TRY_LOOP="20"
SLUGIFY_USES_TEXT_UNIDECODE=yes

BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$BRANCH" == 'master' ]
then
   ${REDIS_HOST:="airflow-celery.xxxxx.0001.use1.cache.amazonaws.com"}
else [ "$BRANCH" == 'QA' ]
   ${REDIS_HOST:="qa-airflow-celery.xxxx.ng.0001.use1.cache.amazonaws.com"}
fi

: ${REDIS_PORT:="6379"}

if [ "$BRANCH" == 'master' ]
then
  ${POSTGRES_HOST:="airflow-database.xxxxx.us-east-1.rds.amazonaws.com"}
  ${POSTGRES_USER:="airflow"}
else [ "$BRANCH" == 'QA' ]
  ${POSTGRES_HOST:="qa-airflow-database.xxxxx.us-east-1.rds.amazonaws.com"}
  ${POSTGRES_USER:="airflow"}
fi  

如果这不起作用,请使用此解决方案
https://stackoverflow.com/a/35586785/7804876

第一个错误是因为airflow的图片不包含git

/entrypoint.sh: line 6: git: command not found

简单的方法是将 git 安装命令作为第一行添加到 entrypoint.sh 文件中。 对于 Debian 发行版:

apt install -y git

如果是 RHEL 分布:

yum -y install git

这种方法的缺点是安装需要一些时间。
你最好为图像添加 git 依赖

  1. 使用docker run 命令运行映像,但不使用--entrypoint entrypoint.sh
  2. 检查容器ID
    docker ps
    对于示例,容器 ID 为 c3f279d17e0a
  3. docker exec -it c3f279d17e0a bash
  4. 如上所述使用 apt/yum 手动安装 git,然后通过依次键入 ctrl+pctrl+q 来分离 bash。
  5. 提交新图片
    docker commit c3f279d17e0a airflow-git:version1

    将容器的文件更改或设置提交到新映像中会很有用。这允许您通过运行交互式 shell 来调试容器,或者将工作数据集导出到另一台服务器。通常,最好使用 Dockerfiles 以记录和可维护的方式管理您的图像。

https://docs.docker.com/engine/reference/commandline/commit/

现在你有了图像airflow-git:version1,用你原来的运行命令--entrypoint entrypoint.sh运行它,它应该可以工作了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-29
    • 2016-02-06
    • 2019-08-03
    • 1970-01-01
    • 1970-01-01
    • 2019-08-12
    相关资源
    最近更新 更多