Reputation: 23
CMD ["./run-nginx.sh"] script doesn't execute and throws panic: standard_init_linux.go:175: exec user process caused "exec format error" [recovered]. Why so? Could you help :( my machine is win10 and docker version : Docker version 1.12.3,
Dockerfile
FROM nginx
ADD run-nginx.sh /usr/app/src/
ADD setup-index-page.sh /usr/app/src/
WORKDIR /usr/app/src/
RUN chmod +x run-nginx.sh
RUN chmod +x setup-index-page.sh
CMD ["./run-nginx.sh"]
run-nginx.sh
#!/usr/bin/env bash
./setup-index-page.sh
exec nginx -g 'daemon off;'
setup-index-page.sh
#!/usr/bin/env bash
container_id=${hostname}
color=${container_id:0:6} echo "<body>Serving you from container id: ${hostname}</body>" > /usr/share/nginx/html/index.html
Response
panic: standard_init_linux.go:175: exec user process caused "exec format error" [recovered]
panic: standard_init_linux.go:175: exec user process caused "exec format error"
2017-01-01T06:48:38.776636000Z
goroutine 1 [running, locked to thread]:
panic(0x88f8a0, 0xc820136a10)
Upvotes: 2
Views: 4969
Reputation: 2694
If you use a script as the entry point for your container, it may have somehow had DOS carriage returns added to the ends of the lines. As a result, your shebang will appear to the Linux shell as #!/bin/bash^M
. The ^M
may be invisible in vim. To see it, run:
vim -U NONE -u NONE filename
To remove it, from inside vim run:
:%s/\r//g
NOTE: Make sure to run vim with above options first.
The most common cause of this is editing files in Windows. However, it will also happen if you created the file by running cat
with docker exec
and the -t
flag. The -t
flag causes execution in TTY mode, which prints DOS carriage returns at the ends of the lines. Instead run without any flags:
docker exec mycontainer cat /path/to/file > file_on_host
Upvotes: 0
Reputation: 623
Given the fact that you are mapping the volume from Windows to Linux, it is very likely that your *.sh files have Windows style (CRLF) line endings. If you convert them to Unix/Linux style (LF), it should be fine to go.
I am not sure about the right tools on Windows to check and fix the line endings but Notepad++ should be able to do it.
Upvotes: 3
Reputation: 16305
I tested your codes on my system with a linux docker backend ( osx actually, so there's no question about what docker backend OS is running), and it worked fine ( though I didn't get a container ID). I think your issue is that you've configured docker in your windows environment to run windows containers, not linux.
Upvotes: 1