2017-06-04 55 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