2017-06-04 90 views
0

这里是the official tutorial创建mongoDB img。从Docker官方教程创建MongoDB图像错误

我严格遵循教程,并生成以下Dockerfile

# https://docs.docker.com/engine/examples/mongodb/#creating-a-dockerfile-for-mongodb 
# Dockerizing MongoDB: Dockerfile for building MongoDB images 
# Based on ubuntu:latest, installs MongoDB following the instructions from: 
# http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/ 

# Format: FROM repository[:version] 
FROM  ubuntu:latest 

# Installation: 
# Import MongoDB public GPG key AND create a MongoDB list file 
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 
RUN apt-get install -y --no-install-recommends software-properties-common 
RUN echo "deb http://repo.mongodb.org/apt/ubuntu $(cat /etc/lsb-release | grep DISTRIB_CODENAME | cut -d= -f2)/mongodb-org/3.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list 


# Update apt-get sources AND install MongoDB 
RUN apt-get update && apt-get install -y mongodb-org 

# MongoDB requires a data directory. Let’s create it as the final step of our installation instructions. 
# Create the MongoDB data directory 
RUN mkdir -p /data/db 

# Expose port 27017 from the container to the host 
EXPOSE 27017 

# Set usr/bin/mongod as the dockerized entry-point application 
ENTRYPOINT ["/usr/bin/mongod"] 

但是,当我执行

$ docker build --tag my/repo . 

我得到了以下错误:

enter image description here

这是怎么回事上?为什么失败?如何解决它?

编辑:

调整命令命令后,我最终的脚本是这样的:

# Format: FROM repository[:version] 
FROM  ubuntu:latest 


# Update apt-get sources AND install MongoDB 
RUN apt-get update 

# Installation: 
# Import MongoDB public GPG key AND create a MongoDB list file 
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 
RUN apt-get install -y --no-install-recommends software-properties-common 
# RUN echo "deb http://repo.mongodb.org/apt/ubuntu $(cat /etc/lsb-release | grep DISTRIB_CODENAME | cut -d= -f2)/mongodb-org/3.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list 
RUN echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list 

RUN apt-get install -y mongodb-org 

# MongoDB requires a data directory. Let’s create it as the final step of our installation instructions. 
# Create the MongoDB data directory 
RUN mkdir -p /data/db 

# Expose port 27017 from the container to the host 
EXPOSE 27017 

# Set usr/bin/mongod as the dockerized entry-point application 
ENTRYPOINT ["/usr/bin/mongod"] 

然后我得到了以下错误:enter image description here

下一步,然后我补充说:“RUN APT-得到安装sudo“,然后我得到以下错误:

enter image description here enter image description here

3击倒,我不确定这整件事情会奏效。这是我最后的Dockerfile。

# https://docs.docker.com/engine/examples/mongodb/#creating-a-dockerfile-for-mongodb 
    # Dockerizing MongoDB: Dockerfile for building MongoDB images 
    # Based on ubuntu:latest, installs MongoDB following the instructions from: 
    # http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/ 

# Format: FROM repository[:version] 
FROM  ubuntu:latest 


# Update apt-get sources AND install MongoDB 
RUN apt-get update 

# Installation: 
# Import MongoDB public GPG key AND create a MongoDB list file 
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 
RUN apt-get install -y --no-install-recommends software-properties-common 

RUN apt-get install sudo 

# RUN echo "deb http://repo.mongodb.org/apt/ubuntu $(cat /etc/lsb-release | grep DISTRIB_CODENAME | cut -d= -f2)/mongodb-org/3.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list 
RUN echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list 

RUN apt-get install -y mongodb-org 

# MongoDB requires a data directory. Let’s create it as the final step of our installation instructions. 
# Create the MongoDB data directory 
RUN mkdir -p /data/db 

# Expose port 27017 from the container to the host 
EXPOSE 27017 

# Set usr/bin/mongod as the dockerized entry-point application 
ENTRYPOINT ["/usr/bin/mongod"] 

如果你能使它工作,请粘贴你的Dockerfile,我很想知道我的脚本中有什么问题。我跟着教程,它不起作用。

+0

当您搜索该错误消息时,Google会说些什么? – Soviut

+0

@Soviut很多结果,我无法识别相关性。 –

回答

0

快速谷歌搜索您发现的确切错误消息this

这是apt的错误,表示无法在其存储库中找到software-properties-common软件包。当找到包更改时,通常意味着需要更新。

您正在运行apt-get update但您正在运行之后的更新行。

RUN apt-get install -y --no-install-recommends software-properties-common 
... 
RUN apt-get update && apt-get install -y mongodb-org 

相反,运行第一

RUN apt-get update 
RUN apt-get install -y --no-install-recommends software-properties-common 
... 
RUN apt-get install -y mongodb-org 

更新:您的更新安装说MongoDB的包,当你现在得到一个错误。这是因为您已经加载了一个deb程序包文件,并且需要再次更新apt以便它知道它。在这一点上,最简单的事情只是在任何apt-get命令的前面,它们抱怨没有找到包含update的包。

RUN apt-get update && apt-get install -y --no-install-recommends software-properties-common 
... 
RUN apt-get update && apt-get install -y mongodb-org 
+0

非常感谢!它通过了这一步,但得到了新的错误“E:找不到软件包mongodb-org”。我无法根据谷歌搜索结果修复它。 –

+0

@ NicolasS.Xu我已经更新了我的答案,以包含monogo未安装的解决方案。 – Soviut