Running clamav in Docker under Linux

I’m running ClamAV [1] on an Ubuntu 18.04 server in Docker and wanted to document, for posteriority and my own dementia, the setup process and considerations.

Thankfully there is an official (?), well-maintained ClamAV image on Docker hub. ClamAV can run stand-alone or as a tandem of CLI tool and daemon – I prefer the latter because it defers signature updating from the time of scanning and supports multi-threading, which the stand-alone version doesn’t.

The script which runs the ClamAV daemon in a container. The container auto-restarts and mounts a socket file, which speeds up communication between the client and the daemon. A weekly cron job runs the script, just to make sure the signature database is updated.


cd "$base"
echo pulling new clamav image
docker pull clamav/clamav:stable || exit 1 

mkdir "$base/sockets"
mkdir "$base/signaturedb"

chmod -R a+rwx "$base/sockets"
chmod -R a+rwx "$base/signaturedb"

echo removing old clamd container
docker stop clamd || echo no container running 
docker rm clamd || echo no clamd container found
docker run \
    --name "clamd" \
    --volume /home/george/clamav/signaturedb:/var/lib/clamav \
    --volume "$dirtoscan":/scandir:ro \
    --mount type=bind,source=$base/sockets/,target=/tmp/ \
    -d \
    --restart always \

And the script which starts the ClamAV scan tool. A monthly cron job runs the script on the entire server.



docker stop clamscan || echo clamscan container not running
docker rm clamscan || echo clamscan container not found
echo running clamscan

docker run -it --rm \
    --name "clamscan" \
    --volume /:/scandir:ro \
    --mount type=bind,source=$base/sockets/,target=/tmp/ \
    --user root \
    clamav/clamav:stable_base \
    clamdscan /scandir

Make sure clamd started properly before running the scan.


[1] ClamAV project page

[2] ClamAV on Docker hub

2 thoughts on “Running clamav in Docker under Linux

  1. Hi George,
    Hope you are doing good!

    While following your document, I am getting below error.

    ERROR: Could not connect to clamd on LocalSocket /tmp/clamd.sock: No such file or directory

    Kindly comment here the soultion if possible


    1. Hello Vinod. Please wait for clamd to start – on my laptop that takes about half a minute. You can look at the logs with “docker logs -f clamd” and wait for a “clamd started” message. I refactored the code a bit and updated the description.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.