Docker throws error standard_init_linux.go:228: exec user process caused: exec format error when there are issues with executable file format. It could happen due to these reasons –
- You forgot to put #!/bin/bash at the top of
shell
files. - There is a space before shebang (
#!/bin/bash
). - Newline character encoding is wrong (
LF
/CRLF
) - Using
#!/bin/bash
instead of #!/bin/ash foralpine
images. - Architecture mismatch like running
x86
image onARM
systems. - Script encoding issue –
UTF8 + BOM
Error due to #!/bin/bash
There are few things regarding shebang.
- There should not be anything before it. Shebang should be the first text in the shell file. Check for spaces, empty lines, hidden characters etc. before it.
- Always include it in the shell files. This proves that the file is executable.
- Use the right command. If it’s a bash file, use
#!/bin/bash
, if shell file then use#!/bin/sh
and if alpine image then#!/bin/ash
. -
Don’t forget
#
. People use to forget it.
Character Encoding (LF
/CRLF
)
Character encoding is an underdog which creates a number of issues in coding. This happens due to new line styles of various operating systems. For example –
- Windows uses CRLF (Carriage Return Line Feed). It’s new line is
\r\n
. - Linux uses LF (Line Feed). It’s new line is
\n
.
When you create codes on Windows, the files uses CRLF encoding. After you deploy them on Linux container it creates encoding issues.
Sometimes this creates standard_init_linux.go:228: exec user process caused: exec format error. So, it’s a good practice to change encoding preferences in your code editors like vscode
and notepad++
to LF
on Windows.
Architecture Mismatch (x86
/ ARM
)
This is the most common issue of exec format error. Take care of these points –
-
Apple M1 is not of same architecture as of Apple Intel chip. Apple M1 has
AMD64
architecture while intel isARM
. - See if you are running 32bit or 64bit operating system.
- You can’t build image on
ARM
and run onAMD64
.
Solution is to use buildx
utility of Docker –
# Build for ARM64 docker buildx build --platform=linux/arm64 -t <image-name>:<version>-arm64 . # Build for AMD64 docker buildx build --platform=linux/amd64 -t <image-name>:<version>-amd64 .
Script encoding (UTF8 + BOM
)
Script encoding also seems to be causing issues. Especially on windows systems. So, you will need to check if your executable file is saved as UTF8
or UTF8+BOM
. BOM stands for Byte Order Mark. Generally, UTF8 files works fine.
Conclusion
The above mentioned solutions will surely resolve your error of standard_init_linux.go:228: exec user process caused: exec format. First look for ARM or x86 architecture issue. Check if the image is build for your Docker architecture. Then, if the issue persists, check the shebang. If still it’s not solved, then go with other solutions here.
Kubernetes Series
- Introduction to Kubernetes
- Introduction to Docker, Containers, Images & Repository
- Install and Run Docker Images
- Docker Image – FROM, RUN, COPY, ENTRYPOINT, CMD, EXPOSE explained
- Why docker run or start command not running my container?
- How to list all docker images in system?
- How to list all docker containers?
- How to start/stop a docker container?
- Difference between docker run and docker start
- How to bind docker container port with host?
- How to get logs of docker container?
- How to live stream logs of docker container?
- Set custom name to a docker container
- Access docker container filesystem & terminal
- Getting docker details using docker inspect
- Kyverno – Installation, Policies, Testing, Reporting, Monitoring, Security
- Complete Kubernetes Project Step By Step
- Introduction to Kubernetes Objects