当前位置: 首页 > 知识库问答 >
问题:

BIND-用docker-compose装入单个文件

齐英韶
2023-03-14
  - ./a/src/:/var/www/html/
  - ./a/config/local.php.ini:/usr/local/etc/php/conf.d/local.ini

每当我更改主机上./a/src目录或/var/www/html/容器中的内容时,它就会在另一边按预期进行更改。他们和他们应该做的一样。

档案就不是这样了。它被复制(我猜)到容器中。但是,如果更改主机上的local.php.ini/usr/local/etc/php/conf.d/local.ini,则另一个文件将保持不变。

那是预期的行为吗?如果是,为什么和是否有可能改变它,这两个文件是相同的与目录

注意:这不是如何在卷中装入单个文件的重复。我得到我的文件作为文件,而不是作为目录或这样。尽管如此,我还是尝试了使用${PWD}的绝对目录,但没有改变。

Docker version 19.03.1, build 74b1e89
docker-compose version 1.24.1, build 4667896b

主机和容器系统是Debian的。

共有1个答案

桓修能
2023-03-14

请把这个过一遍。

我猜可能是因为这个原因造成的。

如果您使用vim这样的文本编辑器编辑文件,那么当您保存文件时,它不会直接保存文件,而是创建一个新文件并将其复制到适当位置。这就破坏了基于inode的绑定挂载。由于保存文件会有效地更改inode,因此更改不会传播到容器中。重新启动容器将获得新的inode,并且更改将得到反映。

# Create a file on host and list it contents and its inode number
-------------------
$ echo 'abc' > /root/file.txt
$ cat /root/file.txt 
abc
$ ls -ltrhi /root/
total 4K     
1623230 -rw-r--r--    1 root     root           4 Aug 23 17:44 file.txt
$
# Run an alpine container by mounting this file.txt
---------------------
$ docker run -itd -v /root/file.txt:/var/tmp/file.txt alpine sh
d59a2ad308d2de7dfbcf042439b295b27370e4014be94bc339f1c5c880bf205f
$
# Check file contents of file.txt and its inode number inside alpine container
$ docker exec -it d59a2ad308d2 sh
/ # cat /var/tmp/file.txt 
abc
/ # ls -ltrhi /var/tmp/
total 4K     
1623230 -rw-r--r--    1 root     root           4 Aug 23 17:44 file.txt
/ #

## NOTE: The inode number of file.txt is same here 1623230 on host and inside the container.

# Edit the file.txt inside alpine container using some text editor like vi
--------------------------
/ # vi /var/tmp/file.txt 
/ # ls -ltrhi /var/tmp/
total 4K     
1623230 -rw-r--r--    1 root     root           5 Aug 23 17:46 file.txt
/ # cat /var/tmp/file.txt 
abcd
/ #

# Check content of file.txt on host, it will be the same as the one inside container since the inode number of file.txt inside container and on host is still same 1623230 
--------------------------
$ cat /root/file.txt   <<=== ran it on host
abcd

# Now edit content of file.txt on host and check its inode number.
$ vi file.txt 
$ ls -ltrhi /root/
total 4K     
 862510 -rw-r--r--    1 root     root           6 Aug 23 17:47 file.txt
$ cat file.txt 
abcde
$ 

## NOTE: the inode number of file.txt on host is changed to 862510 after editing the file using vi editor.

# Check content of file.txt inside alpine container and list it inode number
----------------------------
$ docker exec -it d59a2ad308d2 sh
/ # ls -ltrhi /var/tmp/
total 4K     
1623230 -rw-r--r--    0 root     root           5 Aug 23 17:46 file.txt
/ # cat /var/tmp/file.txt 
abcd
/ #

## NOTE: inode number here is the old one and doesn't match with the one on the host and hence the content of file.txt also doesn't match.

# Restart alpine container
---------------------------
$ docker restart d59a2ad308d2
d59a2ad308d2
$ docker exec -it d59a2ad308d2 sh
/ # cat /var/tmp/file.txt 
abcde
/ # ls -ltrhi /var/tmp/
total 4K     
 862510 -rw-r--r--    1 root     root           6 Aug 23 17:47 file.txt
/ # [node1] (local) root@192.168.0.38 ~
$ 

## NOTE: After restarting container, the inode of file.txt is matching with the one on host and so the file contents also match.
 类似资料:
  • 对于本地开发人员,我需要在Docker容器中装入一个不同的配置文件。使用命令行就很容易实现。是否可以从文件中的(使用创建)执行此操作?

  • 首先,让我声明我不是Linux用户中最有道德的,所以对我来说...下面是我所采取的所有步骤的简要说明。最终的问题/问题是,我似乎不可能下载一个合适的docker-compose安装。 null null “第1行:not:未找到命令”。 docker-compose文件的大小似乎只有9KB。因为这就是我每次使用上面提到的docker-compose安装序列时得到的结果。 这个问题在这里得到了解决:

  • 安装Compose Compose的安装有多种方式,例如通过shell安装、通过pip安装、以及将compose作为容器安装等等。本文讲解通过shell安装的方式。其他安装方式如有兴趣,可以查看Docker的官方文档:https://docs.docker.com/compose/install/ 下载docker-compose ,并放到/usr/local/bin/ curl -L https

  • 我正在运行docker compose测试;我的堆栈中执行实际测试的部分是以下服务 命令失败如下: 正在装载的文件确实存在: 此外,当试图将装载绑定到一个不存在的文件时,我没有得到与装载相关的错误,而是得到了与上面相同的错误 我错过了什么? 编辑:关于提到的问题,这里是: 此外,测试仪的服务配置与本项目完全相同,运行良好。 关于权限问题:

  • Compose的使用非常简单,只需要编写一个docker-compose.yml ,然后使用docker-compose 命令操作即可。docker-compose.yml 描述了容器的配置,而docker-compose 命令描述了对容器的操作。我们首先通过一个示例快速入门: 还记得前文,我们使用Dockerfile为项目microservice-discovery-eureka 构建Docke