user2301
user2301

Reputation: 1967

docker build failed : Not able to set the environment variables

I am trying to build a QT application using docker. I have visual studio 2015 build tools and QT 5.11.2 as base docker image. When I try to docker build QT application, I get this error.

C:\Qt\5.11.2\msvc2015_64\include\QtCore/qglobal.h(45): fatal error C1083: Cannot open include file: 'type_traits': No such file or directory

When I checked for this file 'type_traits', inside docker it exists inside this path:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include

The docker build fails at this step:

RUN C:\\Qt\\Tools\\QtCreator\\bin\\jom.exe

This command RUN ["C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat", "x86_amd64"] sets up the environment variables, How to verify that these still exist for the rest of the RUN commands in dockerfile?

Below is my docker file:

#My base docker image containing QT5.11.2 and Visual build tools 2015    
FROM qt 

COPY ["./", "C:/app"]

RUN $env:PATH ='C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin;' + $env:PATH;\
    [Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine);

RUN $env:PATH ='C:\Qt\5.11.2\msvc2015_64\bin;' + $env:PATH;\
   [Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine);

RUN $env:PATH ='C:\Qt\Tools\QtCreator\bin\jom.exe;' + $env:PATH;\
   [Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine);

RUN $env:PATH ='C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include;' + $env:PATH;\
    [Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine);

WORKDIR C:\\app
RUN ["C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat", "x86_amd64"]

RUN qmake app.pro -spec win32-msvc "CONFIG+=debug" "CONFIG+=qml_debug"  
RUN C:\\Qt\\Tools\\QtCreator\\bin\\jom.exe qmake_all 
RUN C:\\Qt\\Tools\\QtCreator\\bin\\jom.exe    
RUN C:\\Qt\\Tools\\QtCreator\\bin\\jom.exe install
RUN mkdir dist\debug_build\app_dist  
RUN xcopy app_dist\dist_redist\*.* dist\debug_build\app_dist /E /Y >NUL

CMD cmd

Upvotes: 2

Views: 722

Answers (1)

Mike Kinghan
Mike Kinghan

Reputation: 61630

How to verify that these still exist for the rest of the RUN commands in dockerfile?

They won't.

In the environment that exists here

RUN ["C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat", "x86_amd64"]

executes a process that executes the batch file with argument x86_amd64, creating new environment settings for any child processes - of which there are none - then exits. Then:

RUN qmake app.pro -spec win32-msvc "CONFIG+=debug" "CONFIG+=qml_debug"

executes another process in the environment that existed there, which is still the environment. And so on.

There's nothing specific to Docker, or Windows, about this behaviour. In any operating system, a process cannot modify the environment of its parent, only the copy of that environment that it inherits and passes to any child processes.

If you want all of the commands:

qmake app.pro -spec win32-msvc "CONFIG+=debug" "CONFIG+=qml_debug"
C:\\Qt\\Tools\\QtCreator\\bin\\jom.exe qmake_all
C:\\Qt\\Tools\\QtCreator\\bin\\jom.exe
C:\\Qt\\Tools\\QtCreator\\bin\\jom.exe install

to start in an environment modified by vcvarsall.bat x86_amd64, then you have run all of them in the same shell as that command, e.g.

RUN "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat" x86_amd64 && ^
    qmake app.pro -spec win32-msvc "CONFIG+=debug" "CONFIG+=qml_debug"  && \
    C:\\Qt\\Tools\\QtCreator\\bin\\jom.exe qmake_all && \
    C:\\Qt\\Tools\\QtCreator\\bin\\jom.exe && \
    C:\\Qt\\Tools\\QtCreator\\bin\\jom.exe install

See also the dockerfile ENV command for a way of making global environment settings in a docker container.

Upvotes: 1

Related Questions