下面是创建mongoDB img的the official tutorial。
我完全按照教程生成了下面的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 .
我得到了以下错误:
怎么一回事?为什么它会失败?如何修复它?
编辑:
调整命令顺序后,我的最终脚本如下:
# 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"]
然后我得到了以下错误:
接下来,我添加了"RUN apt-get install sudo",然后我得到了以下错误:
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,我很想知道我的脚本中有什么地方错了。我遵循了教程,但它不起作用。
发布于 2017-06-05 02:07:36
在谷歌上快速搜索你的确切错误信息,找到了this。
这是一个来自apt
的错误,说它在其存储库中找不到software-properties-common
包。当发现包有变化时,通常意味着apt需要更新。
您正在运行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,以便它知道它。此时,要做的最简单的事情就是在任何抱怨找不到带有update
的包的apt-get
命令前加上前缀。
RUN apt-get update && apt-get install -y --no-install-recommends software-properties-common
...
RUN apt-get update && apt-get install -y mongodb-org
https://stackoverflow.com/questions/44357201
复制相似问题