standard_init_linux.go:228: exec user process caused: exec format error

standard_init_linux go 228 exec user process caused exec format error

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 –

  1. You forgot to put #!/bin/bash at the top of shell files.
  2. There is a space before shebang (#!/bin/bash).
  3. Newline character encoding is wrong (LF/CRLF)
  4. Using #!/bin/bash instead of #!/bin/ash for alpine images.
  5. Architecture mismatch like running x86 image on ARM systems.
  6. Script encoding issue – UTF8 + BOM

Error due to #!/bin/bash

There are few things regarding shebang.

  1. 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.
  2. Always include it in the shell files. This proves that the file is executable.
  3. 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.
  4. 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.

changing character encoding (CR/LF/CRLF)

Architecture Mismatch (x86 / ARM)

This is the most common issue of exec format error. Take care of these points –

  1. Apple M1 is not of same architecture as of Apple Intel chip. Apple M1 has AMD64 architecture while intel is ARM.
  2. See if you are running 32bit or 64bit operating system.
  3. You can’t build image on ARM and run on AMD64.

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.


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.