Docker多阶段-如果基础映像不同,则Args不会持久

问题描述

我正在尝试使用多阶段创建图像,但它没有按预期工作。

考虑此docker文件

httpSecurity.antMatcher("/foo/**").csrf().disable().sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().authorizeRequests()
            .antMatchers("/foo/test/{testId}/**")
            .access("@fooApiGuard.check(authentication,#testId)");

@Service
public class FooApiGuard {

    @Autowired
    private HttpServletRequest request;

    public boolean check(Authentication authentication,Long testId) throws AuthenticationException {
        // check stuff
        return true;
    }
}

我得到的输出

FROM microsoft/iis:nanoserver
ARG A
RUN echo %A%

FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8
ARG A
RUN echo %A% World 

我只是使用-build-arg A = hello

传递了'A'arg

输出中可以看到,“ A”的值在下一阶段被重置。 但是,如果我在“ FROM”命令中使用相同的基本映像,则该值将保留到下一个阶段。

为什么会这样?这是预期的行为吗?

最后我如何将'A'的值保留到下一个阶段?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)