Last updated: Apr 13, 2024
Reading time·4 min
The Docker error "standard_init_linux.go: exec user process caused "exec format error" occurs for multiple reasons:
#!/bin/bash
to the top of your .sh
file (e.g.
entrypoint.sh
).x86
architecture on an
arm64
or aarch64
machine.utf-8-bom
). Use the basic utf-8
encoding instead.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).
#!/bin/bash
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.
#!/usr/bin/env bash
If you use Alpine Linux (without bash), add the following line at the top of
your .sh
file.
#!/bin/ash
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.
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
.
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
.
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.
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.
Another thing you need to verify is that your script file was saved using the
correct encoding (utf-8
).
Make sure to set the file to be encoded using utf-8
.
For example, if your current encoding is utf-8-bom
or utf-32
, utf-16
, etc,
switch the encoding to utf-8
.
After you switch the encoding, rebuild your Docker image.
I've written a detailed guide on how to change the file encoding in Visual Studio Code.
To solve the Docker error "standard_init_linux.go: exec user process caused "exec format error", make sure:
#!/bin/bash
character sequence at the
start of your script.