将Makefile变量传递给docker-compose会导致”未知的速记标志错误”。

huangapple go评论60阅读模式
英文:

Passing Makefile variable to docker-compose is resulting in a "unknown shorthand flag" error

问题

我有一个Makefile,我用它来帮助我们的程序员轻松设置环境。目前,我正在编写一个Makefile来将IMAGE标签传递给docker-compose命令,但我一直收到一个unknown shorthand flag错误,我无法弄清楚原因。

我的Makefile如下:

.PHONY: all

ARCH = $(shell uname -m)

start:
	if [ "$(ARCH)" = "x86_64" ]; then \
  		IMAGE_ARCH="amd64"; \
	elif [ "$(ARCH)" = "aarch64" ]; then \
		IMAGE_ARCH="arm64"; \
	else \
		echo "Unknown architecture: $(ARCH)"; \
	fi

	docker-compose up -d -e IMAGE=$IMAGE_ARCH

错误信息是:

unknown shorthand flag: 'e' in -e
英文:

I have a Makefile which I use to help our programmers get easily setup. At present I am writing one to pass an IMAGE tag to the docker-compose command, but I keep getting a unknown shorthand flag and I cant figure out why.

My Makefile is as follows;

.PHONY: all

ARCH = $(shell uname -m)

start:
	if [ "$(ARCH)" = "x86_64" ]; then \
  		IMAGE_ARCH="amd64"; \
	elif [ "$(ARCH)" = "aarch64" ]; then \
		IMAGE_ARCH="arm64"; \
	else \
		echo "Unknown architecture: $(ARCH)"; \
	fi

	docker-compose up -d -e IMAGE=$IMAGE_ARCH

The error is;

unknown shorthand flag: 'e' in -e

答案1

得分: 1

docker-compose没有-e选项。

你可以这样运行:

.PHONY: all

ARCH := $(shell uname -m)

start:
    if [ "$(ARCH)" = "x86_64" ]; then \
        IMAGE_ARCH="amd64"; \
    elif [ "$(ARCH)" = "aarch64" ]; then \
        IMAGE_ARCH="arm64"; \
    else \
        echo "Unknown architecture: $(ARCH)"; \
    fi; \
    IMAGE=$$IMAGE_ARCH docker-compose up -d

docker-compose命令需要放在与[if]相同的块中,以便使用$IMAGE_ARCH。

英文:

docker-compose has no -e option.

You can run this way :

.PHONY: all

ARCH := $(shell uname -m)

start:
    if [ "$(ARCH)" = "x86_64" ]; then \
        IMAGE_ARCH="amd64"; \
    elif [ "$(ARCH)" = "aarch64" ]; then \
        IMAGE_ARCH="arm64"; \ 
    else \   
        echo "Unknown architecture: $(ARCH)"; \
    fi; \ 
    IMAGE=$$IMAGE_ARCH docker-compose up -d

docker-compose command needs to be put in the same block as [if] in order to use $IMAGE_ARCH.

huangapple
  • 本文由 发表于 2023年2月18日 15:06:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75491745.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定