【问题标题】:Cannot replace the software source inside docker Ubuntu image无法替换 docker Ubuntu 映像中的软件源
【发布时间】:2017-04-10 12:59:20
【问题描述】:

我在docker上安装了Ubuntu 14.04镜像。镜像自带Ubuntu官方软件源。由于我在中国无法连接这些服务器,必须编辑etc/apt/source.list替换软件使用 vi 或 vim 获取源。但是,Ubuntu 映像没有附带这两个编辑器中的任何一个。如果我试过 要安装编辑器,我必须更改软件源。我该如何解决这个问题?

【问题讨论】:

  • 从基础镜像创建一个派生镜像,并在其中编写脚本以使用 sed 更改源
  • 感谢您的回复,但我不知道如何使用sed。我使用 dockerfile 解决了这个问题。

标签: ubuntu docker vim


【解决方案1】:

您可以按如下方式创建派生的 docker 映像:

Dockerfile

FROM ubuntu:14.04
COPY ./sources.list /etc/apt/

sources.list(我以前在中国用过,效果不错,换成你喜欢的)

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to                                                                                                                               
# newer versions of the distribution.
deb http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-updates main restricted
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://cn.archive.ubuntu.com/ubuntu/ trusty universe
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty universe
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-updates universe
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-updates universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://cn.archive.ubuntu.com/ubuntu/ trusty multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu trusty-security main restricted
deb-src http://security.ubuntu.com/ubuntu trusty-security main restricted
deb http://security.ubuntu.com/ubuntu trusty-security universe
deb-src http://security.ubuntu.com/ubuntu trusty-security universe
deb http://security.ubuntu.com/ubuntu trusty-security multiverse
deb-src http://security.ubuntu.com/ubuntu trusty-security multiverse
## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu trusty partner
# deb-src http://archive.canonical.com/ubuntu trusty partner
## This software is not part of Ubuntu, but is offered by third-party
## developers who want to ship their latest software.
#deb http://extras.ubuntu.com/ubuntu trusty main
#deb-src http://extras.ubuntu.com/ubuntu trusty main

创建这些文件后,您可以通过运行以下命令来构建映像:

docker build --tag ubuntu:14.04-cn

并在您的项目中使用它,如果您需要将其上传到 docker hub,您将需要相应地更改名称。

此外,我建议您直接在映像中安装所需的软件,这样您就不必每次启动容器时都安装依赖项,这也是因为无论如何您都在构建映像。

【讨论】:

  • 感谢您的详细回放和有用的建议。我是初学者,所以我需要摸索很多。
  • 如果答案正确解决了您的问题,请将其标记为正确,以便其他人以后可以使用相同的系统。如果不让我知道您是否无法正常工作,我可以对其进行修改。
猜你喜欢
  • 2015-02-01
  • 2020-10-18
  • 2022-08-23
  • 2016-10-03
  • 2021-09-05
  • 1970-01-01
  • 1970-01-01
  • 2013-05-19
  • 1970-01-01
相关资源
最近更新 更多