Docker | CentOS | $releasever is "" when running docker build

TT4M.C asked:

I am attempting to build a docker image from a CentOS parent image … and installing MongoDB. The error is happening when docker build is adding the MongoDB repo.

You can see that the error is happening because $releasever is blank for some reason.


FROM centos:latest
MAINTAINER "MyName" <[email protected]>
ENV container docker
RUN echo -e "\
name=MongoDB Repository\n\
gpgkey=\n" >> /etc/yum.repos.d/mongodb-org-4.0.repo
RUN yum repolist all
RUN yum install -y mongodb-org

ERROR [Errno 14] HTTPS Error 404 - Not Found

My answer:

You didn’t escape the $, thus the variable $releasever was interpreted in your shell, instead of being inserted literally into the echo command output.

Try \$releasever.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.