![相同的 make 命令在 macOS 中失败,但在 Linux 中成功](https://linux22.com/image/204643/%E7%9B%B8%E5%90%8C%E7%9A%84%20make%20%E5%91%BD%E4%BB%A4%E5%9C%A8%20macOS%20%E4%B8%AD%E5%A4%B1%E8%B4%A5%EF%BC%8C%E4%BD%86%E5%9C%A8%20Linux%20%E4%B8%AD%E6%88%90%E5%8A%9F.png)
我在下面使用Makefile
,make publish
在 macOS 上失败,而在 Linux(alpine、Ubuntu、Debian)上成功,并出现以下错误:
$ make publish
"docker images" requires at most 1 argument.
See 'docker images --help'.
Usage: docker images [OPTIONS] [REPOSITORY[:TAG]]
List images
"docker inspect" requires at least 1 argument.
See 'docker inspect --help'.
Usage: docker inspect [OPTIONS] NAME|ID [NAME|ID...]
Return low-level information on Docker objects
=> Publishing release image to some_image:tag ...
=> Publish complete
make publish
some_image:tag
使用.push 推送之前构建的 Docker 镜像make image_build
。
生成文件如下:
ORG_NAME ?= some_name
REPO_NAME ?= some_name
CHECK := @bash -c '\
if [[ $(INSPECT) -ne 0 ]]; \
then exit $(INSPECT); fi' VALUE
DOCKER_REGISTRY ?= [some_docker_registry]
.PHONY: build image_build tag login logout publish
build:
${INFO} "Building artifacts..."
${INFO} "Building artifacts complete"
image_build:
${INFO} "Building images..."
@ docker build -t $(DOCKER_REGISTRY)/$(ORG_NAME)/$(REPO_NAME) .
${INFO} "Building complete..."
tag:
${INFO} "Tagging release image with tags $(TAG_ARGS)..."
@ $(foreach tag,$(TAG_ARGS), docker tag $(DOCKER_REGISTRY)/$(ORG_NAME)/$(REPO_NAME):latest $(DOCKER_REGISTRY)/$(ORG_NAME)/$(REPO_NAME):$(tag);)
${INFO} "Tagging complete"
login:
${INFO} "Logging in to Docker registry $$DOCKER_REGISTRY..."
@ docker login -u $$DOCKER_USER -p $$DOCKER_PASSWORD $(DOCKER_REGISTRY)
${INFO} "Logged in to Docker registry $$DOCKER_REGISTRY"
logout:
${INFO} "Logging out of Docker registry $$DOCKER_REGISTRY..."
@ docker logout $(DOCKER_REGISTRY)
${INFO} "Logged out of Docker registry $$DOCKER_REGISTRY"
publish:
${INFO} "Publishing release image to $(DOCKER_REGISTRY)/$(ORG_NAME)/$(REPO_NAME)..."
@ $(foreach tag,$(shell echo $(REPO_EXPR)), docker push $(tag);)
${INFO} "Publish complete"
IMAGE_ID := $$(docker images -q $(DOCKER_REGISTRY)/$(ORG_NAME)/$(REPO_NAME):latest)
# Repository Filter
ifeq ($(DOCKER_REGISTRY), docker.io)
REPO_FILTER := $(ORG_NAME)/$(REPO_NAME)[^[:space:]|\$$]*
else
REPO_FILTER := $(DOCKER_REGISTRY)/$(ORG_NAME)/$(REPO_NAME)[^[:space:]|\$$]*
endif
# Introspect repository tags
REPO_EXPR := $$(docker inspect -f '{{range .RepoTags}}{{.}} {{end}}' $(IMAGE_ID) | grep -oh "$(REPO_FILTER)" | xargs)
# Cosmetics
YELLOW := "\e[1;33m"
NC := "\e[0m"
# Shell Functions
INFO := @bash -c '\
printf $(YELLOW); \
echo "=> $$1"; \
printf $(NC)' SOME_VALUE
# Extract tag arguments
ifeq (tag,$(firstword $(MAKECMDGOALS)))
TAG_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
ifeq ($(TAG_ARGS),)
$(error You must specify a tag)
endif
$(eval $(TAG_ARGS):;@:)
endif
想知道如何调试此类问题以及可能的原因是什么?
latest
尝试从 line 中删除IMAGE_ID := $$(docker images -q $(DOCKER_REGISTRY)/$(ORG_NAME)/$(REPO_NAME):latest)
,但没有任何反应:
$ make publish
=> Publishing release image to some_image:tag
=> Publish complete
make
macOS 版本:
$ make --version
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for i386-apple-darwin11.3.0
答案1
编辑
实际上,在再次查看 Makefile 后,我注意到“docker”命令抱怨缺少参数,这意味着它无法找到您之前构建的映像
publish:
${INFO} "Publishing release image to $(DOCKER_REGISTRY)/$(ORG_NAME)/$(REPO_NAME)..."
${INFO} "$(IMAGE_ID)"
@ $(foreach tag,$(shell echo $(REPO_EXPR)), docker push $(tag);)
$ make publish
"docker inspect" requires at least 1 argument.
See 'docker inspect --help'.
Usage: docker inspect [OPTIONS] NAME|ID [NAME|ID...]
Return low-level information on Docker objects
=> Publishing release image to ****...
=>
=> Publish complete
如果图像存在,则发布步骤将正常工作
$ make publish
=> Publishing release image to ***** ...
The push refers to repository [*****k]
90f9b3de67de: Pushed
latest: digest: sha256:af045c36b459f251b41b2db6b98320b7fdc1d6a2146b17a15344ec0e0a89b6f5 size: 527
=> Publish complete
所以你需要确保提前执行“image_build”步骤