【问题标题】:Docker build fails when executed within Makefile在 Makefile 中执行 Docker 构建失败
【发布时间】:2019-03-08 13:27:44
【问题描述】:

所以,我有一个我测试过的 Docker 构建命令,效果很好

docker build \
  -t app \
  --no-cache --network host \
  --build argssh_private_key="$(cat ~/.ssh/id_rsa)"\
  --build-arg python_version="3.6.8" -f Dockerfile .

为了减轻团队学习 Docker 的痛苦,我将一些命令(构建、启动、停止)封装在 Makefile 中。但是,在 Makefile 中,我需要通过修改来稍微更改命令

$(cat ~/.ssh/id_rsa)

$(shell cat ~/.ssh/id_rsa)

当我执行以下操作时:

make build

我收到以下消息:

Step 13/20 : RUN git clone --depth 1 "${git_user}@${git_host}:${git_repo}" app
---> Running in d2eb41a71315
Cloning into 'app'...
Warning: Permanently added the ECDSA host key for IP address [ip_address] to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

但是,从命令行执行时,我没有遇到同样的问题。我认为这与调用“cat”命令的方式有关,但是我不知道解决方法。

有什么想法吗?

生成文件:

APP_NAME=ccs_data_pipeline
DATA?="${HOME}/data"
DOCKER_FILE=Dockerfile
PYTHON_VERSION?=3.6.8
SRC?=$(shell dirname `pwd`)
PRIVATE_KEY?=$(shell echo $(shell cat ~/.ssh/id_rsa))

build: ## Build container for ccs data pipeline
  docker build \
    -t $(APP_NAME) \
    --no-cache --network host \
    --build-arg ssh_private_key="$(PRIVATE_KEY)" \
    --build-arg python_version="$(PYTHON_VERSION)" \
    -f $(DOCKER_FILE) .

start: ## Start the docker container
  docker run \
    -it -v $(DATA):/data \
    --network host \
    --rm \
    --name="$(APP_NAME)" $(APP_NAME)
        
stop: ## Stop the docker container
  docker stop $(APP_NAME); \
  docker rm $(APP_NAME)

【问题讨论】:

    标签: bash makefile dockerfile


    【解决方案1】:

    请显示您的实际生成文件,或至少显示出现错误的整个规则。您提供的单个命令,没有上下文,不足以理解您在做什么或可能出了什么问题。

    请注意,将$(...) 之类的shell 操作替换为make shell 命令$(shell ...) 通常是不正确的。但是,有时它会“偶然”起作用,而这些命令之间的真正差异并不重要。

    一般来说,你不应该在配方中使用$(shell ...)(我不知道这个命令是否出现在配方中)。相反,当 shell 运行你的配方时,你应该转义你想要逐字传递给 shell 的所有美元符号:

    $$(cat ~/.ssh/id_rsa)
    

    【讨论】:

    • 您将此答案标记为已接受。这是否意味着您的示例可以正常工作并且不需要更多帮助?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-13
    相关资源
    最近更新 更多