简体   繁体   English

在文件中删除卷引用后,停止 docker compose 卷安装在容器中

[英]Stop docker compose volume from mounting in container after volume reference removed in file

I am currently running a custom built docker container using a docker compose file.我目前正在使用 docker compose 文件运行自定义构建的 docker 容器。 The docker compose file looks as follows: docker compose 文件如下所示:

version: '2'
services:
  ubuntu:
    privileged: true
    image: custom_docker_image:17
    container_name: custom_docker_container
    command: '/usr/bin/supervisord'
    volumes:
       - /custom_docker_path/public:/public
       - /custom_docker_path/data/logs:/data/logs
       - /custom_docker_path/var/log:/var/log
       - /custom_docker_path/etc/nginx:/etc/nginx
       - /custom_docker_path/etc/supervisor:/etc/supervisor
       - /etc/letsencrypt:/etc/letsencrypt
    ports:
       - '9202:9200'

The docker container runs services and processes which are kept alive using supervisor. docker 容器运行服务和进程,这些服务和进程使用主管保持活动状态。 Everything ran as expected until I changed the volume mounting.一切都按预期运行,直到我更改了卷安装。

The file previously use to have the volumes as follows:该文件以前用于具有如下卷:

version: '2'
services:
  ubuntu:
    privileged: true
    image: custom_docker_image:17
    container_name: custom_docker_container
    command: '/usr/bin/supervisord'
    volumes:
       - /custom_docker_path/public/db:/public/db
       - /custom_docker_path/public/settings:/public/settings
       - /custom_docker_path/data/logs:/data/logs
       - /custom_docker_path/var/log:/var/log
       - /custom_docker_path/etc/nginx:/etc/nginx
       - /custom_docker_path/etc/supervisor:/etc/supervisor
       - /etc/letsencrypt:/etc/letsencrypt
    ports:
       - '9202:9200'

Previously, only the db and settings folders in the public directory in the container where shared with the host machine.以前,只有容器中公共目录中的 db 和 settings 文件夹与主机共享。 I then decided to share the entire public directory with the host machine.然后我决定与主机共享整个公共目录。

The sharing was successful, except the db and settings folders were still being shared along with the entire public directory.共享成功,除了dbsettings文件夹仍然与整个公共目录一起共享。

Running the mount command inside the container shows the following:在容器内运行mount命令显示以下内容:

/dev/mapper/host_machine_mount root on /public type ext4 (rw,relatime,errors=remount-ro,data=ordered)
/dev/mapper/host_machine_mount root on /data/logs type ext4 (rw,relatime,errors=remount-ro,data=ordered)
/dev/mapper/host_machine_mount root on /public/db type ext4 (rw,relatime,errors=remount-ro,data=ordered)
/dev/mapper/host_machine_mount root on /public/settings type ext4 (rw,relatime,errors=remount-ro,data=ordered)
/dev/mapper/host_machine_mount root on /etc/supervisor type ext4 (rw,relatime,errors=remount-ro,data=ordered)
/dev/mapper/host_machine_mount root on /etc/letsencrypt type ext4 (rw,relatime,errors=remount-ro,data=ordered)
/dev/mapper/host_machine_mount root on /var/log type ext4 (rw,relatime,errors=remount-ro,data=ordered)
/dev/mapper/host_machine_mount root on /etc/nginx type ext4 (rw,relatime,errors=remount-ro,data=ordered)

From the above, /public gets mounted and so does /public/db and /public/settings even though they are not referenced in the new docker-compose file.从上面可以看出, /public被挂载, /public/db/public/settings也是如此,即使它们在新的 docker-compose 文件中没有被引用。

I elevated privileges in the container to manually remove the mounts after the container starts up and that works - but I can't keep entering the container and removing the two mount points.我提升了容器中的权限,以便在容器启动后手动删除挂载,这有效 - 但我无法继续进入容器并删除两个挂载点。

I also tried removing the volumes outside docker and pruning but the two directories still mount inside the container on startup.我还尝试删除 docker 和 pruning 之外的卷,但是这两个目录在启动时仍然挂载在容器内。

Tried running:尝试运行:

docker-compose down -v

docker volume rm "volume_name"

docker volume prune

Tried above commands while container was running, stopped and before and after restarts.在容器运行、停止以及重新启动之前和之后尝试了上述命令。

How do I stop these two directories from mounting inside the container?如何阻止这两个目录安装在容器内?

Try using docker-compose down -v to remove all containers AND volumes declared in your docker-compose.yml尝试使用docker-compose down -v删除在 docker-compose.yml 中声明的所有容器和卷

https://docs.docker.com/compose/reference/down/ https://docs.docker.com/compose/reference/down/

-v, --volumes Remove named volumes declared in the volumes section of the Compose file and anonymous volumes attached to containers. -v, --volumes 删除在 Compose 文件的volumes部分中声明的命名卷和附加到容器的匿名卷。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM