title: CGO_Enabled=1 required building Go binary using SQLite in Alpine Docker container
body: <p>I am trying to compile an Alpine Go container which uses <a href="https://gorm.io/docs/connecting_to_the_database.html#SQLite" rel="nofollow noreferrer">GORM</a> and it's <a href="https://github.com/go-gorm/sqlite" rel="nofollow noreferrer">SQLite driver</a> for an in-memory database. This depends on CGO being enabled. My binary builds and executes fine using <code>go build .</code>, but when running my docker image (<code>docker build .</code> followed by <code>docker run $imagename</code>) I get the error message:</p>
  <pre><code>standard_init_linux.go:219: exec user process caused: no such file or directory
  </code></pre>
  <p>I am building on Windows 10 64 bit. I have gcc installed. Both <code>C:\TDM-GCC-64\bin</code> and <code>C:\cygwin64\bin</code> are in my $env:path. I have changed the line endings to Linux style (LF) for all files in the package.</p>
  <p>My docker file is as follows:</p>
  <pre><code>FROM golang:1.16.4-alpine AS builder
  
  RUN apk update \
      &amp;&amp; apk add --no-cache git \
      &amp;&amp; apk add --no-cache ca-certificates \
      &amp;&amp; apk add --update gcc musl-dev \
      &amp;&amp; update-ca-certificates
  
  # Create a user so that the image doens't run as root
  RUN adduser \
      --disabled-password \
      --gecos &quot;&quot; \
      --home &quot;/nonexistent&quot; \
      --shell &quot;/sbin/nologin&quot; \
      --no-create-home \
      --uid &quot;100001&quot; \
      &quot;appuser&quot;
  
  # Set the working directory inside the container.
  WORKDIR $GOPATH/src/app
  
  # Copy all files from the current directory to the working directory
  COPY . .
  
  # Fetch dependencies.
  RUN go get -u -d -v
  
  # Go build the binary, specifying the final OS and architecture we're looking for
  RUN GOOS=linux CGO_ENABLED=1 GOARCH=amd64 go build -ldflags=&quot;-w -s&quot; -o /go/bin/app -tags timetzdata
  
  FROM scratch
  
  # Import the user and group files from the builder.
  COPY --from=builder /etc/passwd /etc/passwd
  COPY --from=builder /etc/group /etc/group
  COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
  
  # Copy our static executable.
  COPY --from=builder /go/bin/app/go/bin/app
  
  # Use the user that we've just created, one that isn't root
  USER appuser:appuser
  
  ENTRYPOINT [&quot;/go/bin/app&quot;]
  </code></pre>
  <p>Can you please help me understand why my docker image won't run?</p>
  <p>In case it's of any value, the line of Go code to open the DB is like so. As this works using Go build locally or using <code>go run .</code> I don't think this is relevant however.</p>
  <pre><code>db, err := gorm.Open(sqlite.Open(&quot;file::memory:?cache=shared&quot;), &amp;gorm.Config{})
  </code></pre>