Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RUN echo -e "deb http ... " prepares a wrong contents of the target file

Host with Ubuntu 16.04.2.

Docker version 17.06.0-ce.

Dockerfile

RUN echo -e "deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx\ndeb-src http://nginx.org/packages/mainline/ubuntu/ xenial nginx" | tee /etc/apt/sources.list.d/nginx.list

This results in in /etc/apt/sources.list.d/nginx.list:

-e deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx
deb-src http://nginx.org/packages/mainline/ubuntu/ xenial nginx

Well, as if interpretation of backslash escapes works. But this "-e" has occurred in the file.

And then such image can't be built.

Could you give me a kick here?

like image 308
Michael Avatar asked Aug 06 '17 13:08

Michael


1 Answers

Try using the bash shell for the echo command instead. Docker by default uses the sh shell and for some reason it doesn't like the -e characters and had echo'ed it as part of its input.

To fix this;

Update to:

RUN bash -c 'echo -e "deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx\ndeb-src http://nginx.org/packages/mainline/ubuntu/ xenial nginx" | tee /etc/apt/sources.list.d/nginx.list'

Outputs:

root@87944d07f493:/etc/apt/sources.list.d# cat nginx.list deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx deb-src http://nginx.org/packages/mainline/ubuntu/ xenial nginx

You can replicate this "docker problem" by switching to sh on your current terminal session and then do the same echo command again.

like image 72
Samuel Toh Avatar answered Oct 13 '22 11:10

Samuel Toh