28

I use the Docker ClamAV image in my docker-compose.yml like this:

version: '3.7'
services:
  clamav_updater:
    image: quay.io/ukhomeofficedigital/clamav:latest
    ports:
      - "3310:3310"
    volumes:
      - type: bind
        source: /home/misc/docker/efs_clamav
        target: /var/lib/clamav

This service is planned to be the "updater"/"writer". This means it will download updates into /var/lib/clamav, and since this is a mounted volume with source: /home/misc/docker/efs_clamav - the reader nodes (that will not run the update command) will be able to get the updated files from that folder.

This is all in theory. In practice, when I run this image I get the following error:

ERROR: for clamav_writer Cannot create container for service clamav_writer: Duplicate mount point: /var/lib/clamav

I understand that this is due to the fact that the Dockerfile already set the same directory as a volume:

VOLUME /var/lib/clamav

Is there anyway I can still set that volume in my docker-compose.yml file (so that I can set the source directory for other readers to read from?

4
  • 15
    try docker-compose down && docker-compose up command , let me know is it solve your problem ...
    – hs-dev2 MR
    Commented Jul 1, 2019 at 8:49
  • Can't replicate issue from example docker-compose.yml
    – Rach Sharp
    Commented Jul 1, 2019 at 10:55
  • @RachSharp the container runs fine for you this way? You are able to share the files between /var/lib/clamav and your host dir?
    – Cauthon
    Commented Jul 1, 2019 at 11:24
  • I wasn't checking for actually getting the service to be functional, from your question it seemed like the issue was the startup process failing due to the multiple volume definitions - I didn't get the error message you provided on startup, instead failing later on in the process
    – Rach Sharp
    Commented Jul 1, 2019 at 13:17

7 Answers 7

58

A comment from @hs-dev2 looks like the right answer:

docker-compose down; then docker compose up

1
  • This fixes symptoms and not solve the problem. Consider anwer by @4269237 Commented May 28, 2021 at 10:13
7

Just in case anyone is still having this issue, it looks like this is the bugfix, which will presumably be released in the version after Docker Desktop v3.4.0:

https://github.com/docker/compose-cli/pull/1782

And the workaround until that makes it into the production docker compose cli is to make sure to use the exact same path (either with or without trailing slash) in the Dockerfile and the docker-compose.yml

2
  • Wow that trailing slash caused me so much trouble! This answer needs to be upvoted
    – Guerrilla
    Commented Jul 17, 2021 at 5:09
  • I got stuck in the same problem for 4 hours until I came across this comment. Why isn't this the accepted answer?
    – Sachin
    Commented Jan 3, 2022 at 15:59
5

This issue seams to occur when you have multiple volume declarations mostly in docker-compose.yml and Dockerfile. The solution is to remove VOLUME declaration in your Dockerfile or docker-compose.yml eg.

version: '3.5'
services:
    test:
        build: .
        volumes: 
        - /mnt/tmpfs

Docker file:

FROM alpine:3.4

VOLUME /mnt/tmpfs

CMD /bin/sh

I removed the one from the Dockerfile.

0
0

For me a combination of both the answers fixed the problem.

Even though I didn't have a duplicate but I had Docker compose in another project with same named volume and same mount path.

The solution was to change the mount path temporarily from

volumes:
      - db-data:/var/lib/postgresql/data 

to,

volumes:
      - db-data:/var/lib/postgresql/data/somethingelse 

And then I gave docker compose up and then docker compose down. This cleared the existing mount points.

Finally I reverted my changes to the yaml, Now even the old path works fine.

0
0

Upgrading docker-compose from version 1 (v1.29.2) to version 2 (v2.2.3) fixed it for me.

Note that the installation process is different - and so is the command to run: in version 1, it's docker-compose; in 2, it's docker compose (i.e. it's a subcommand of docker)

0

This is how the bind mounts works for docker/container volume.

There are three types of Volumes in the docker/container.

-v volumeID:volumePath // Called as Named Volume

-v "HostMachineAbsolutePath:ContainerVolumePath" // Bind Mounts

-v FilesToIgnoreCopyingFromHostToContainerVolume //Called as anonymous volume

Let's talk about the duplicate mount point error.

This happens because if the named volume path(volumePath) is exact the same as bind mounts ContainerVolumePath. Both paths should not be the same otherwise you will get a duplicate mount point error.

This how it looks like as an example

 docker run -p  30056:30056 -d -v volumeID:volumePath -v "HostMachineAbsolutePath:ContainerVolumePath" -v FilesToIgnoreCopyingFromHostToContainerVolume --name v1C mahesh:v2;

Actual command (example):

 docker run -p  30056:30056 -d -v dock-volume:/DockerDemo/storage -v "/Users/maheshvirus/DockerDemo/app:/DockerDemo/app" -v /DockerDemo/app/node_modules --name v1C mahesh:v2; 

Here is a great example of Named Volumes vs Anonymous Volumes vs Bind Mounts.

enter image description here

0

Very similar case (Error response from daemon: fill out specgen: /data: duplicate mount destination) on linux fedora (where docker is podman) for Redis docker.io/redis/redis-stack-server:latest.

Solved by upgrading to Docker Compose version v2.15.1.

Not the answer you're looking for? Browse other questions tagged or ask your own question.