docker - 在运行的 docker 容器中安装包

标签 docker dockerfile apt

我一直在使用 docker 容器来构建 Chrome 浏览器(在 Debian 10 上为 Android 构建)。我已经创建了一个 Dockerfile,其中包含我需要的大部分包。
现在,在构建并运行容器后,我遵循了 instructions ,它要求我执行安装脚本 (./build/install-build-deps-android.sh)。在这个脚本中,执行了多个 apt install 命令。
我现在的问题是,有没有办法在不重建容器的情况下安装这些包?下载和构建它花费了相当长的时间,再加上每次需要新包时重建一个容器似乎都不是最理想的。执行安装脚本时出现的错误是:

./build/install-build-deps-android.sh: line 21: lsb_release: command not found
(我猜会有多个丢失的包)。使用 apt 将给出:
root@677e294147dd:/android-build/chromium/src# apt install nginx
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package nginx
(nginx 仅作为安装示例)。
我很感激任何提示,因为我只能找到使用 Dockerfile 安装软件包的指南。

最佳答案

您可以使用 docker 提交:

  • 启动您的容器 sudo docker run IMAGE_NAME
  • 使用 bash 访问您的容器:sudo docker exec -it CONTAINER_ID bash
  • 在容器内安装任何你需要的东西
  • 退出容器的 bash
  • 提交您的更改:sudo docker commit CONTAINER_ID NEW_IMAGE_NAME

  • 如果您现在运行 docker images , 你会看到 NEW_IMAGE_NAME列在您的本地镜像下。
    下次启动 docker 容器时,使用刚刚创建的新 docker 镜像:sudo docker run **NEW_IMAGE_NAME** - 这将包括您的其他安装。
    根据以下教程回答:How to commit changes to docker image

    关于docker - 在运行的 docker 容器中安装包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63027514/

    相关文章:

    docker-compose 为同一个图像创建多个实例

    python - 如何将 python 命令传递给 dockerfile

    docker - 如何在代理后面的 dockerfile 中运行 `apt-get`?

    linux - 为什么 Ubuntu 或 APT 不使用 rsync 进行更新?

    c++ - 在 C++ 代码中找到正确的实现

    docker - Docker 17无法在Centos 7中启动

    docker - Elixir和Docker

    docker - 为什么使用 `--ignore-pull-failures` 拉取图像第一次显示 404 失败,第二次完成

    docker - 在Docker容器中执行的Java应用程序中运行docker命令

    node.js - Docker:来自守护进程的错误响应:OCI 运行时创建失败:container_linux.go:296: