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

sdnqo3pr  于 2023-02-21  发布在  Docker
关注(0)|答案(1)|浏览(231)

我有一个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
biswetbf

biswetbf1#

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。

相关问题