Tools, FAQ, Tutorials:
"shell" Format vs. "exec" Format
What is the differences between "shell" format and "exec" format when writing instructions in Dockerfile for Windows images?
✍: FYIcenter.com
There are several differences between "shell" format and "exec" format
when writing instructions in Dockerfile for Windows images.
1. The "shell" format is simple to use. But it does support well if any argument has a space character, like path name with spaces in it.
2. The "exec" format can protect spaces in arguments, but it uses the JSON array syntax and it is harder to use.
3. When "shell" format is used in a RUN instruction, the specified program will actually be executed with the CMD program. For example:
RUN program arg1 arg2 # Will be executed as: # Powershell -Command program arg1 arg2
4. When "exec" format is used in a RUN instruction, the specified program will actually be executed directly. For example:
RUN ["program", "arg1", "arg2"] # Will be executed as: # program arg1 arg2
Let's watch the build history of a Dockerfile in "exec" format:
C:\fyicenter> type ExecImage FROM openjdk RUN ["PowerShell", "mkdir", "\"C:\\FYI Center\""] COPY ["Hello.java", "C:/FYI Center/Hello.java"] RUN ["javac", "C:\\FYI Center\\Hello.java"] ENTRYPOINT ["java", "-cp", "C:\\FYI Center", "Hello"] C:\fyicenter> docker build --file ExecImage --tag exec . ... C:\fyicenter> docker history exec IMAGE CREATED BY SIZE 2bffa2d267d3 powershell -Command $ErrorActionPreference =… 41kB -- Resulted from ENTRYPOINT ["java", "-cp", "C:\\FYI Center", "Hello"] a30f5dd0735a javac C:\FYI Center\Hello.java 58.7MB -- Resulted from - RUN ["javac", "C:\\FYI Center\\Hello.java"] 3937cb41e4cf powershell -Command $ErrorActionPreference =… 41.1kB -- Resulted from - COPY ["Hello.java", "C:/FYI Center/Hello.java"] d3757bcbd35f PowerShell mkdir "C:\FYI Center" 40.5MB -- Resulted from - RUN ["PowerShell", "mkdir", "\"C:\\FYI Center\""] ...
Now watch the build history of a Dockerfile in "shell" format:
C:\fyicenter> type ShellImage FROM openjdk RUN PowerShell mkdir C:\fyicenter COPY Hello.java C:/fyicenter/Hello.java RUN javac C:\fyicenter\Hello.java ENTRYPOINT java -cp C:\fyicenter Hello C:\fyicenter> docker build --file ShellImage --tag shell . ... C:\fyicenter> docker history shell IMAGE CREATED BY SIZE d818dc169bd2 powershell -Command $ErrorActionPreference =… 41kB -- Resulted from - ENTRYPOINT java -cp C:\fyicenter Hello fdf64e942a8d powershell -Command $ErrorActionPreference =… 58.9MB -- Resulted from - RUN javac C:\fyicenter\Hello.java 719d9171fefc powershell -Command $ErrorActionPreference =… 41.1kB -- Resulted from - COPY Hello.java C:/fyicenter/Hello.java ab736679b461 powershell -Command $ErrorActionPreference =… 40.5MB -- Resulted from - RUN PowerShell mkdir C:\fyicenter ...
Ok, we are able to see the differences between "shell" format and "exec" format used in Dockerfile.
⇒ Use "ENV" Instruction on Windows Image
⇐ Spaces in Path Name on Windows Images
2021-11-30, 832🔥, 0💬
Popular Posts:
How to run PowerShell Commands in Dockerfile to change Windows Docker images? When building a new Wi...
How To Protect Special Characters in Query String in PHP? If you want to include special characters ...
Where to find tutorials on API Management Services at Azure Portal? Here is a list of tutorials to a...
How to start Visual Studio Command Prompt? I have Visual Studio 2017 Community version with Visual C...
FYIcenter JSON Validator and Formatter is an online tool that checks for syntax errors of JSON text ...