Skip to content

Fix *standard_init_linux.go:XXX: exec user process caused "no such file or directory"* Error

November 17th, 2017 - ITTutorial(1 min)

TL;DR: Use dos2unix

While switching from Ubuntu to Alpine images, I’ve encountered the fillowing error:

standard_init_linux.go:195: exec user process caused “no such file or directory”

Quite unfortunate, because the script stayed in the same spot and only the image changed. After reading a bunch, I figured that it’s the fact that I’m editing on Windows and Alpine doesn’t seem to interpret #/bin/sh properly - adding a ^M :). The solution is to either fix the script locally or to format it as part of the docker build process. I chose the latter as the former depends on the developer.

Since dos2unix is not part of Alpine, one needs to install it. At the time of writing, the package is on the edge branch. Therefore, the install sequence would be:

RUN echo >> /etc/apk/repositories
RUN echo >> /etc/apk/repositories
RUN apk add --no-cache dos2unix

We copy the script and post-process it:

COPY ./ /
RUN chmod +x /

RUN dos2unix /

At this point, the script is primed for execution and the error is practically fixed.


In the quest to reduce the docker image, the actual sequence is:

COPY ./ /
RUN chmod +x /

# Convert to unix the script
RUN echo >> /etc/apk/repositories && \
    echo >> /etc/apk/repositories && \
    apk add --no-cache --virtual .build-deps dos2unix  && \
    dos2unix /  && \
    apk del .build-deps  && \
    rm -rf /var/cache/apk/*

This will ensure dos2unix is removed at the end of processing.


Share on

A little experiment: