首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >通过Docker官方教程创建MongoDB镜像错误

通过Docker官方教程创建MongoDB镜像错误
EN

Stack Overflow用户
提问于 2017-06-05 02:00:43
回答 1查看 206关注 0票数 0

下面是创建mongoDB img的the official tutorial

我完全按照教程生成了下面的Dockerfile

代码语言:javascript
运行
复制
# 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"]

但是当我执行

代码语言:javascript
运行
复制
$ docker build --tag my/repo .

我得到了以下错误:

怎么一回事?为什么它会失败?如何修复它?

编辑:

调整命令顺序后,我的最终脚本如下:

代码语言:javascript
运行
复制
# 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。

代码语言:javascript
运行
复制
    # 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,我很想知道我的脚本中有什么地方错了。我遵循了教程,但它不起作用。

EN

回答 1

Stack Overflow用户

发布于 2017-06-05 02:07:36

在谷歌上快速搜索你的确切错误信息,找到了this

这是一个来自apt的错误,说它在其存储库中找不到software-properties-common包。当发现包有变化时,通常意味着apt需要更新。

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

代码语言:javascript
运行
复制
RUN apt-get install -y --no-install-recommends software-properties-common
...
RUN apt-get update && apt-get install -y mongodb-org

相反,应该先运行它

代码语言:javascript
运行
复制
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命令前加上前缀。

代码语言:javascript
运行
复制
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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44357201

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档