Docker Image - exec user process caused "exec format error"

2021-12-06

HIVE

The Problem

I built a Linux dev box docker image with some necessary run time environments such as go and python, but it didn't run and raised the error message exec user process caused "exec format error".

The Cause

I spent more than an hour finding the solution as nothing looked wrong for me. I have tried different docker image build options but no luck.

After multiple attempts, I discovered the error message disappeared after I passed commands directly rather than using the run.sh in the DockerFile.

So the problem is actually from the run.sh file and I forgot to put the shebang.

The Solution

Put the bash shebang at the beginning of the file and the problem is resolved, so simple.

Old "run.sh":

# Start SSH service ssh restart && bash tail -f /dev/null

New "run.sh":

#!/bin/bash # Start SSH service ssh restart && bash tail -f /dev/null