gpt4 book ai didi

linux - 用于创建镜像、安装软件(同时创建镜像)和启动容器的 Docker 进程

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:03:51 24 4
gpt4 key购买 nike

我有一个简单的 Dockerfile:

来自 ubuntu
CMD 易于获取更新;易于升级; apt-get install -y openjdk-8-jdk python2.7 python-pip unzip libaio1 nano tree curl wget alien

在我的主机 (Mac) 上,从上面 Dockerfile 所在的同一文件夹运行此命令以创建图像:
docker build 。 -t 我的-linux

这需要一两分钟,然后检查使用 docker images 创建的图像:
存储库标记图像 ID 创建大小
my-linux 最新 f9061de79d89 34 秒前 112MB
ubuntu 最新 f975c5035748 2 周前 112MB

接下来,我基于图像运行(创建容器):docker run -it my-linux bash

尝试安装的软件:
root@79a49eab5342:/# nano
bash:nano:找不到命令
root@79a49eab5342:/#

为什么没有安装“nano”? (以及其他软件)

最佳答案

通过Docker Docs :

The main purpose of a CMD is to provide defaults for an executing container.

通过Docker Docs :

The RUN instruction will execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in the Dockerfile.

所以你应该使用RUN而不是CMD

此外,在您的 Dockerfile 中,您可以:

CMD ["bash"]

这将自动执行 bash 并将您带入 shell,因此您在执行 docker run 时不必执行 -it。它将带您直接进入 shell。

关于linux - 用于创建镜像、安装软件(同时创建镜像)和启动容器的 Docker 进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49481893/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com