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

  docker, docker-compose, linux, mount, volumes

I am currently running a custom built docker container using a docker compose file.
The docker compose file looks 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:/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.
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. 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.

Running the mount command inside the container shows the following:

/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.

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.

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?

Source: Docker Questions

One Reply to “Stop docker compose volume from mounting in container after volume reference removed in file”

Leave a Reply to jim Cancel reply