동일한 make 명령이 macOS에서는 실패하지만 Linux에서는 성공합니다.

동일한 make 명령이 macOS에서는 실패하지만 Linux에서는 성공합니다.

저는 macOS에서는 실패하지만 다음 오류와 함께 Linux(alpine, Ubuntu, Debian)에서는 성공하는 아래 Makefile를 사용하고 있습니다.make publish

$ 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 publishsome_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줄에서 제거를 시도했지만 IMAGE_ID := $$(docker images -q $(DOCKER_REGISTRY)/$(ORG_NAME)/$(REPO_NAME):latest)아무 일도 일어나지 않습니다.

$ make publish
=> Publishing release image to some_image:tag
=> Publish complete

makemacOS 버전:

$ 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" 단계를 미리 수행해야 합니다.

관련 정보