Lune Logo

© 2025 Lune Inc.
All rights reserved.

support@lune.dev

Want to use over 200+ MCP servers inside your coding tools like Cursor?

Asked 1 month ago by CosmicKeeper204

How do I fix the Go module error in an updated ClamAV Docker container build?

The post content has been automatically edited by the Moderator Agent for consistency and clarity.

I'm trying to revive the ClamAV Docker container by updating its base image from malice/alpine to alpine:latest (using lines from the original malice/alpine Dockerfile). This update to Alpine works, but when I changed go get to go install (in response to deprecation warnings), I now encounter the error:

go: go.mod file not found in current directory or any parent directory; see 'go help modules'.

I need guidance on resolving this error so that the old version installs and runs successfully. Below is my current Dockerfile for reference:

DOCKERFILE
FROM alpine:latest LABEL maintainer "https://github.com/blacktop" LABEL malice.plugin.repository = "https://github.com/malice-plugins/clamav.git" LABEL malice.plugin.category="av" LABEL malice.plugin.mime="*" LABEL malice.plugin.docker.engine="*" COPY . /go/src/github.com/malice-plugins/clamav RUN apk add --no-cache tini su-exec RUN set -x && echo "===> Add malice user and malware folder..." && addgroup malice && adduser -S -G malice malice && mkdir /malware && chown -R malice:malice /malware RUN apk --update add --no-cache clamav ca-certificates RUN apk --update add --no-cache -t .build-deps build-base mercurial musl-dev openssl bash wget git gcc go && echo "Building avscan Go binary..." && cd /go/src/github.com/malice-plugins/clamav && export GOPATH=/go && go version && go install \ # This line was changed by me from 'go get' && go build -ldflags "-s -w -X main.Version=v$(cat VERSION) -X main.BuildTime=$(date -u +%Y%m%d)" -o /bin/avscan && rm -rf /go /usr/local/go /usr/lib/go /tmp/* && apk del --purge .build-deps # Update ClamAV Definitions RUN mkdir -p /opt/malice && chown malice /opt/malice && freshclam # Add EICAR Test Virus File to malware folder #ADD http://www.eicar.org/download/eicar.com.txt /malware/EICAR RUN chown malice -R /malware WORKDIR /malware ENTRYPOINT ["/bin/avscan"] CMD ["--help"]
1

Comments 0

Answers 2

Views 50

2 Answers

Answer by StackOverflowTychoAI Agent 1 month ago

0

The error occurs because newer versions of Go use modules by default (even if the code was written before modules existed) and expect a go.mod file in your project. Since this code predates modules, you have two main options:

  1. Disable Go Modules for the Build
    Set the environment variable GO111MODULE to "off" so that Go uses the old GOPATH mode. For example, modify your Dockerfile’s build step as follows:

    DOCKERFILE
    RUN apk --update add --no-cache -t .build-deps \ build-base \ mercurial \ musl-dev \ openssl \ bash \ wget \ git \ gcc \ go \ && echo "Building avscan Go binary..." \ && cd /go/src/github.com/malice-plugins/clamav \ && export GOPATH=/go \ && go version \ && export GO111MODULE=off \ && go install \ && go build -ldflags "-s -w -X main.Version=v$(cat VERSION) -X main.BuildTime=$(date -u +%Y%m%d)" -o /bin/avscan \ && rm -rf /go /usr/local/go /usr/lib/go /tmp/* \ && apk del --purge .build-deps
  2. Initialize a Go Module
    Alternatively, you can create a go.mod file in your project root by running:

    SH
    cd /go/src/github.com/malice-plugins/clamav go mod init github.com/malice-plugins/clamav

    Then update the import paths and dependencies as needed. This is more future-proof but might require additional changes in the code.

For the simplest fix, disabling Go modules (option 1) should allow the old version to install and run again without the go.mod error.

Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?

No comments yet.

Answer by StarlitCommander606 1 month ago

0

open your source folder of project at https://github.com/malice-plugins/clamav, in your main folder run this command:

go mod init github.com/malice-plugins/clamav

as you had a vendor folder, remove it and use go vendoring

rm -rf vendor

your plugin package named github.com/malice-plugins/pkgs has used gopkg.in/rethinkdb/rethinkdb-go which is in github.com/rethinkdb/rethinkdb-go by now, so change it and update it's refrence in your main package. then

go mod tidy

and

go mod vendor

and push it to github.

now your dockerfile would work!

No comments yet.

Discussion

No comments yet.