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.

DockerFile

FROM centos:latest
MAINTAINER "MyName" <[email protected]>
ENV container docker
RUN echo -e "\
[mongodb-org-4.0]\n\
name=MongoDB Repository\n\
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/\n\
gpgcheck=1\n\
enabled=1\n\
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc\n" >> /etc/yum.repos.d/mongodb-org-4.0.repo
RUN yum repolist all
RUN yum install -y mongodb-org

ERROR

https://repo.mongodb.org/yum/redhat//mongodb-org/4.0/x86_64/repodata/repomd.xml: [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.