#
exec user process caused: exec format error
[Solved]
The Docker error "standard_init_linux.go: exec user process caused "exec
format error" occurs for multiple reasons:
-
Forgetting to add
#!/bin/bash
to the top of your
.sh
file (e.g.
entrypoint.sh
).
-
Trying to run a Docker image that was built on
x86
architecture on an
arm64
or
aarch64
machine.
-
Using the incorrect line endings for your operating system, e.g. using CRLF
(Windows) line endings used on a Unix machine (LF).
-
Using an incorrect encoding, e.g. saving the file with a BOM (Byte Order
Mark) encoding (e.g.
utf-8-bom
). Use the basic
utf-8
encoding instead.
#
Add the shebang character sequence at the top of your script
The first thing you need to ensure is to add the shebang character sequence at
the top of your script (the
.sh
file).
For example, for a bash script, you would add the following line at the top
(must be the first line).
Make sure there are no spaces in front of the line and the character sequence is
not misspelled.
If that doesn't work, you can also try the following line.
If you use Alpine Linux (without bash), add the following line at the top of
your
.sh
file.
The line has to be the very first line in your shell script, otherwise, it won't
work.
If you get the
"standard_init_linux.go:: exec user process caused "no such
file or directory"
error, then you are probably on an Alpine architecture that
doesn't have a bash shell and you need to use
#!/bin/ash
(instead of
#!/bin/bash
) as shown in the previous code sample.
#
The image might be built with a different architecture
Another common cause of the error is when your image is built with a different
architecture than the one on your server.
In this case, you need to rebuild the image using the correct architecture.
For example, your image might be built using
x86
(32-bit), so it cannot be
used on an
arm64
(64-bit) or
aarch64
(64-bit) machine.
You might also have an image that was built on an
arm64
architecture and is
attempted to be run on
amd64
.
Conversely, you would also get the error if you try to run an
amd64
image on a non-amd64 machine (e.g. ARM or 32-bit).
If you have an ARM-based chip, the Docker build command will assume
arm64
.
This is often the case if you have a
MacBook Pro
.
You can use the
--platform
parameter to specify the platform when running the
docker build
command.
For example, assuming
ARM64
(ARM architecture that supports 64-bit
processing).
docker buildx build --platform=linux/arm64 -t <IMAGE_NAME>:<IMAGE_VERSION>-arm64 .
Make sure to replace the
IMAGE_NAME
and
IMAGE_VERSION
placeholders with the
actual image name and version.
Similarly, if we assume
AMD64
(AMD-developed architecture that supports 64-bit
processing). Also known as
x86-64
,
x64
, and Intel 64.
docker buildx build --platform=linux/amd64 -t <IMAGE_NAME>:<IMAGE_VERSION>-amd64 .
You will also get this error if you build your Docker image on an M1 chip and
upload the image to be run on AWS (e.g. AWS Fargate or AWS ECS).
docker buildx build --platform=linux/amd64 -t <IMAGE_NAME>:<IMAGE_VERSION>-amd64 .
If the error persists after rebuilding the image, update the
FROM
statement in
your
Dockerfile
to also specify the
platform
FROM --platform=linux/amd64 BASE_IMAGE:BASE_IMAGE_VERSION
If you use a sub-image, make sure the
FROM
statement (with
--platform
) is
specified in the parent image's
Dockerfile
.
#
Make sure your shell script is saved using the correct line endings
Another thing you should verify is that your shell script was saved using the
correct line ending characters.
If you are on Windows, the script file should be saved using CRLF
(CarriageReturn + LineFeed) as the end of line sequence.
If you are on macOS or Linux, the file should be saved using LF (LineFeed)
characters for line endings.
You might run into issues if you've saved your script file on Windows (CRFL) and attempt to run it on a Unix (LF) machine (macOS or Linux).
In this case, you need to save the file with Unix line endings (LF).
I've written a detailed guide on
how to set the line endings in Visual Studio code
.
After you save the file with the correct end of line characters, you have to
rebuild your image.
#
Make sure your script file was saved using the correct encoding
Another thing you need to verify is that your script file was saved using the