How to configure different dockerfile for development and production

前端 未结 4 417
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-30 00:49

I use docker for development and in production for laravel project. I have slightly different dockerfile for development and production. For example I am mounting local director

4条回答
  •  悲&欢浪女
    2021-01-30 01:22

    I have tried several approaches to this, including using docker-compose, a multi-stage build, passing an argument through a file and the approaches used in other answers. My company needed a good way to do this and after trying these, here is my opinion.

    The best method is to pass the arg through the cmd. You can pass it through vscode while right clicking and choosing build image Image of visual studio code while clicking image build using this code:

    ARG BuildMode
    RUN echo $BuildMode
    RUN if [ "$BuildMode" = "debug" ] ; then apt-get update \
        && apt-get install -y --no-install-recommends \
           unzip \
        && rm -rf /var/lib/apt/lists/* \
        && curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v latest -l /vsdbg ; fi
    

    and in the build section of dockerfile:

    ARG BuildMode
    ENV Environment=${BuildMode:-debug}
    RUN dotnet build "debugging.csproj" -c $Environment -o /app
    
    FROM build AS publish
    RUN dotnet publish "debugging.csproj" -c $Environment -o /app
    

提交回复
热议问题