I wasted two days on this until I finally figured out my problem, so I thought I'd share. I'll outline the problem I was having here, and then outline the solutions in the answer.
My Dockerfile
looked something like this,
FROM php:7.2-fpm
COPY custom-docker-php-entrypoint /usr/local/bin/
ENTRYPOINT ["custom-docker-php-entrypoint"]
I had a file custom-docker-php-entrypont
in the same directory.
#!/bin/sh
set -e
# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
set -- php "$@"
fi
exec "$@"
However, when I ran docker-compose up -d
and then docker-compose logs -f
my php container show as failing with exit code 1
saying exec user process caused "no such file or directory"
I then loaded up the container with a different entrypoint command and used bash to look inside and confirm that the file was being copied into the location that I expected it to be.
I thought, "Maybe this is a permissions thing?" so I tried setting chmod 777 custom-docker-php-entrypoint
, but that also didn't solve my problem. I also tried setting it to executable with chmod -x custom-docker-php-entrypoint
, but that also didn't help.
So, even though logs say "no such file or directory," the actual problem (at least in my case) was due to the difference in end-of-line (EOL) characters on Windows and Linux. Windows uses CRLF
represent the end of a line and Unix/Linux uses LF
.
I hadn't consider this as a potential problem since the files were freshly cloned from Github and were originally created on Linux. What I didn't know is that on Windows Git is set up to automatically convert EOL characters to CRLF
.
autocrlf
).There are a few ways to go about doing this. autocrlf
is the name of the attribute that decides whether git converts line endings. You'd only need to do one of the following options depending on what you need.
autocrlf
for one commandYou can clone the files with the following to disable autocrlf
as just a one time thing.
git clone https://github.com/someuser/somerepo --config core.autocrlf=false
.gitattributes
If you have a single repo that you know you want to always have autocrlf disabled, you can specify it in that repo's .gitattributes
file. Just add the following line to your .gitattributes
file.
* text eol=lf
autocrlf
in Git's config fileNavigate to the folder where Git is installed on your machine. For me it was installed at C:\ProgramData\Git
. Open config
in a text editor. Change autocrlf=true
to autocrlf=false
.
If you've got existing entrypoint scripts that you need to convert, or if you're writing your entrypoint scripts in Windows in the first place, you can easily set the EOL type with most popular text editors. I'll outline how to do it in Vim, Notepad++, and Sublime, but it should be easy enough to figure out by searching "change EOL" and the name of your text editor of choice.
To change the line endings to be compatible with Linux, do :set ff=unix
. To change them so that they are compatible with Windows, do :set ff=dos
.
On the menu bar click on Edit
and then go to EOL Conversion
and select the desired conversion. You'll want to select Unix (LF)
to make it compatible with Linux.
On the menu bar click 'View' and go to 'Line Endings' and from there select the desired conversion. You'll want to select Unix
to make it compatible with Linux.
Alternatively, there's a useful tool called dos2unix
that you can install in your image and use to convert your entrypoint script. Assuming an Ubuntu or Debian based image which uses apt-get , you can use it in the following way.
FROM php:7.2-fpm
RUN apt-get update && \
apt-get install -y dos2unix
COPY custom-docker-php-entrypoint /usr/local/bin/
RUN dos2unix /usr/local/bin/custom-docker-php-entrypoint
ENTRYPOINT ["custom-docker-php-entrypoint"]
If your Docker image is based on Alpine linux using apk for a package manager, you'll want to do something like this,
FROM alpine:latest
RUN apk --update add bash && \
apk add dos2unix
COPY entrypoint.sh /
RUN dos2unix /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
If your Docker image is based on Centos using yum as a package manager, you'll want to do something like this,
FROM centos:latest
RUN yum update -y && \
yum install dos2unix -y
COPY entrypoint.sh /
RUN dos2unix /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With