在 Dockerfile 中使用 apt-get 安装的应用程序在哪里?

where are apps installed using apt-get within Dockerfile?

我是 Docker 的新手。我在 Windows 机器上。 我写了这个 Docker 文件:

FROM ubuntu:xenial
MAINTAINER myname@mycompany.de
EXPOSE 1883 1883
RUN apt-get update && apt-get install mosquitto -y
CMD ["mosquitto"]

它成功了:我能够构建并启动图像,之后我也能够将客户端连接到 mosquitto-server - 所以这意味着 mosquitto-server 运行ning docker-容器。

作为下一个测试用例,我想覆盖默认的 mosquitto-config-file,所以我想我可以在我的 Docker 文件中使用 ADD 语句(然后重建)。但是因此我需要知道 mosquitto 的安装位置。我通过 ssh 进入 VM,我希望 /etc/mosquitto 中有 mosquitto,但没有这样的文件夹。

1) 蚊子在哪?

2) 为什么我不能 运行 mosquitto ("not found") 而 VM 中的 ssh - 但 CMD ["mosquitto"] 有效?

3) 在我的情况下使用 ADD 是最佳做法吗?

我不确定文件到底存储在哪里,但是在 docker-machine ssh 之后,您可以以 root 身份转到文件夹 /var/lib/docker/aufs/diff/ 或 /var/lib/docker/aufs/mnt/ 并调查您的方式大约。 或者,最好使用 COPY 命令在 Dockerfile 本身中添加自定义配置文件。确保将您的配置文件放在适当的文件夹中,例如 app/config/.. 等

你的mosquitto不在你的虚拟机里面,而是在你的容器里面,要进入你的容器里面(必须是运行)你可以试试:

docker exec -it <containerID> /bin/bash

现在你在你的容器里,你可以找到蚊子。

使用 ADD 是一种很好的做法,但请记住重新构建容器以应用此更改。