Using latest Docker for Mac, on latest macOS.
I have a Dockerfile:
FROM debian:8
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update -y -q \
&& apt-get install -y -q apt-utils \
&& apt-get upgrade -y -q \
&& apt-get install -y -q ssh build-essential libssl-dev libffi-dev python-dev python-pip python-six openjdk-7-jdk \
&& mkdir -p /etc/ansible \
&& echo -e "[ssh_connection]\nssh_args = -o ControlMaster=no -o ControlPersist=60s\n" > /etc/ansible/ansible.cfg
The problem is with the echo command. The content of the file produced by that command is:
-e [ssh_connection]
ssh_args = -o ControlMaster=no -o ControlPersist=60s
The -e option is printed as well! What's even crazier the option has been picked up by echo, as evident by the newlines being parsed. In fact if I attach to a container and run the same command again, I get the correct file content. I thought this might be a problem with docker build
quoting each argument in RUN, but even if I run echo "-e" "X\nY"
the command prints:
X
Y
Does anyone have any idea why this would happen?
Try running:
RUN bash -c 'echo -e ...'
Source
Reading carefully https://github.com/docker/docker/issues/8949, I understand that the reason of the weird behavior depends from the interpreting shell.
In my case, running an Ubuntu image, it was enough to remove the -e to have the line properly formatted:
RUN echo "# User rules for foobar\n\
foobar ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/nopasswd
And the result is:
# User rules for foobar
foobar ALL=(ALL) NOPASSWD:ALL
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