[GH-ISSUE #652] Failed to build Dockerfile: unknown flag -ldflags -w -s #62328

Closed
opened 2026-05-03 08:14:52 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @jamesbraza on GitHub (Sep 29, 2023).
Original GitHub issue: https://github.com/ollama/ollama/issues/652

On an AWS EC2 g4dn.2xlarge instance (Ubuntu 22.04.2 LTS) with Ollama a1b2d95, from a fresh git clone git@github.com:jmorganca/ollama.git:

> sudo docker buildx build . --file Dockerfile
 => => transferring context: 6.93MB                                                                                                                                                                            0.1s
 => [stage-1 2/4] RUN apt-get update && apt-get install -y ca-certificates                                                                                                                                    42.4s
 => [stage-1 3/4] RUN groupadd ollama && useradd -m -g ollama ollama                                                                                                                                          37.6s
 => [stage-0 2/7] WORKDIR /go/src/github.com/jmorganca/ollama                                                                                                                                                 21.9s
 => [stage-0 3/7] RUN apt-get update && apt-get install -y git build-essential cmake                                                                                                                          10.8s
 => [stage-0 4/7] ADD https://dl.google.com/go/go1.21.1.linux-amd64.tar.gz /tmp/go1.21.1.tar.gz                                                                                                                0.8s
 => [stage-0 5/7] RUN mkdir -p /usr/local && tar xz -C /usr/local </tmp/go1.21.1.tar.gz                                                                                                                        3.2s
 => [stage-0 6/7] COPY . .                                                                                                                                                                                     0.1s
 => ERROR [stage-0 7/7] RUN /usr/local/go/bin/go generate ./...     && /usr/local/go/bin/go build .                                                                                                            0.4s
------
 > [stage-0 7/7] RUN /usr/local/go/bin/go generate ./...     && /usr/local/go/bin/go build .:
0.361 go: parsing $GOFLAGS: unknown flag -ldflags -w -s
------
Dockerfile:14
--------------------
  13 |     ENV GOARCH=$TARGETARCH
  14 | >>> RUN /usr/local/go/bin/go generate ./... \
  15 | >>>     && /usr/local/go/bin/go build .
  16 |
--------------------
ERROR: failed to solve: process "/bin/sh -c /usr/local/go/bin/go generate ./...     && /usr/local/go/bin/go build ." did not complete successfully: exit code: 1

The error seems to be:

go: parsing $GOFLAGS: unknown flag -ldflags -w -s

Do you know if I am missing an apt package? Any insight to this error?

Originally created by @jamesbraza on GitHub (Sep 29, 2023). Original GitHub issue: https://github.com/ollama/ollama/issues/652 On an AWS EC2 `g4dn.2xlarge` instance (Ubuntu 22.04.2 LTS) with Ollama [a1b2d95](https://github.com/jmorganca/ollama/tree/a1b2d95f967df6b4f89a6b9ed67263711d59593c), from a fresh `git clone git@github.com:jmorganca/ollama.git`: ```none > sudo docker buildx build . --file Dockerfile => => transferring context: 6.93MB 0.1s => [stage-1 2/4] RUN apt-get update && apt-get install -y ca-certificates 42.4s => [stage-1 3/4] RUN groupadd ollama && useradd -m -g ollama ollama 37.6s => [stage-0 2/7] WORKDIR /go/src/github.com/jmorganca/ollama 21.9s => [stage-0 3/7] RUN apt-get update && apt-get install -y git build-essential cmake 10.8s => [stage-0 4/7] ADD https://dl.google.com/go/go1.21.1.linux-amd64.tar.gz /tmp/go1.21.1.tar.gz 0.8s => [stage-0 5/7] RUN mkdir -p /usr/local && tar xz -C /usr/local </tmp/go1.21.1.tar.gz 3.2s => [stage-0 6/7] COPY . . 0.1s => ERROR [stage-0 7/7] RUN /usr/local/go/bin/go generate ./... && /usr/local/go/bin/go build . 0.4s ------ > [stage-0 7/7] RUN /usr/local/go/bin/go generate ./... && /usr/local/go/bin/go build .: 0.361 go: parsing $GOFLAGS: unknown flag -ldflags -w -s ------ Dockerfile:14 -------------------- 13 | ENV GOARCH=$TARGETARCH 14 | >>> RUN /usr/local/go/bin/go generate ./... \ 15 | >>> && /usr/local/go/bin/go build . 16 | -------------------- ERROR: failed to solve: process "/bin/sh -c /usr/local/go/bin/go generate ./... && /usr/local/go/bin/go build ." did not complete successfully: exit code: 1 ``` The error seems to be: ```none go: parsing $GOFLAGS: unknown flag -ldflags -w -s ``` Do you know if I am missing an `apt` package? Any insight to this error?
Author
Owner

@mchiang0610 commented on GitHub (Sep 30, 2023):

@jamesbraza Would love to help. Just wondering if our docker image does not suffice yet?

https://hub.docker.com/r/ollama/ollama

It's a work in progress

<!-- gh-comment-id:1741686872 --> @mchiang0610 commented on GitHub (Sep 30, 2023): @jamesbraza Would love to help. Just wondering if our docker image does not suffice yet? https://hub.docker.com/r/ollama/ollama It's a work in progress
Author
Owner

@jamesbraza commented on GitHub (Sep 30, 2023):

Oh dang, I thought that was macOS only for some reason. Didn't know it'd work on Ubuntu with GPUs.

I will give it a try next Monday! 👍

One request: can you add instructions to https://hub.docker.com/r/ollama/ollama how to bind to 0.0.0.0 for servers?

<!-- gh-comment-id:1741709752 --> @jamesbraza commented on GitHub (Sep 30, 2023): Oh dang, I thought that was macOS only for some reason. Didn't know it'd work on Ubuntu with GPUs. I will give it a try next Monday! 👍 One request: can you add instructions to https://hub.docker.com/r/ollama/ollama how to bind to `0.0.0.0` for servers?
Author
Owner

@jamesbraza commented on GitHub (Sep 30, 2023):

Thanks for fixing @mxyng! It build successfully for me just now 👍

@mxyng or @mchiang0610, would you mind still answering if the Docker Hub image works on Ubuntu with GPUs? Sorry for being annoying, but if I can just use the Hub image I won't worry about building

<!-- gh-comment-id:1741855740 --> @jamesbraza commented on GitHub (Sep 30, 2023): Thanks for fixing @mxyng! It build successfully for me just now 👍 @mxyng or @mchiang0610, would you mind still answering if the Docker Hub image works on Ubuntu with GPUs? Sorry for being annoying, but if I can just use the Hub image I won't worry about building
Author
Owner

@mxyng commented on GitHub (Oct 2, 2023):

It should. You'll need to install nvidia-container-toolkit to enable GPU support for Docker. Once it's installed, you need an additional --gpus=all parameter to docker run. https://hub.docker.com/r/ollama/ollama has the details

<!-- gh-comment-id:1743398378 --> @mxyng commented on GitHub (Oct 2, 2023): It should. You'll need to install nvidia-container-toolkit to enable GPU support for Docker. Once it's installed, you need an additional `--gpus=all` parameter to `docker run`. https://hub.docker.com/r/ollama/ollama has the details
Author
Owner

@jamesbraza commented on GitHub (Oct 2, 2023):

I will give that a whirl then, thank you @mxyng !

<!-- gh-comment-id:1743594554 --> @jamesbraza commented on GitHub (Oct 2, 2023): I will give that a whirl then, thank you @mxyng !
Author
Owner

@marcellodesales commented on GitHub (Nov 10, 2023):

  • The build should be in a single command...
  • Yet, I can't get it to work because there might be some C compilation going on...
    • That's a lot of details for a new developer...

🐳 Docker Compose Build

  • Local build with the compose above without passing any ARG param
    • Taking the defaults from Dockerfile
 $ docker compose build
[+] Building 3.4s (14/14) FINISHED                                                                                                             docker:desktop-linux
 => [ollama internal] load build definition from Dockerfile.build                                                                                              0.0s
 => => transferring dockerfile: 1.33kB                                                                                                                         0.0s
 => [ollama internal] load .dockerignore                                                                                                                       0.0s
 => => transferring context: 115B                                                                                                                              0.0s
 => [ollama internal] load metadata for docker.io/nvidia/cuda-arm64:11.3.1-devel-centos8                                                                       1.8s
 => [ollama auth] nvidia/cuda-arm64:pull token for registry-1.docker.io                                                                                        0.0s
 => [ollama base-arm64 1/3] FROM docker.io/nvidia/cuda-arm64:11.3.1-devel-centos8@sha256:26ae46571f0767212454c4135bf51f6235d0f4c189f21aab662bf24dd4ff1eff      0.0s
 => [ollama] https://dl.google.com/go/go1.21.3.linux-arm64.tar.gz                                                                                              0.2s
 => [ollama internal] load build context                                                                                                                       0.1s
 => => transferring context: 16.06kB                                                                                                                           0.0s
 => CACHED [ollama base-arm64 2/3] RUN sed -i -e 's/mirrorlist/#mirrorlist/g' -e 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc  0.0s
 => CACHED [ollama base-arm64 3/3] RUN yum install -y git cmake                                                                                                0.0s
 => CACHED [ollama stage-2 1/5] ADD https://dl.google.com/go/go1.21.3.linux-arm64.tar.gz /tmp/go1.21.3.tar.gz                                                  0.0s
 => CACHED [ollama stage-2 2/5] RUN mkdir -p /usr/local && tar xz -C /usr/local </tmp/go1.21.3.tar.gz                                                          0.0s
 => CACHED [ollama stage-2 3/5] WORKDIR /go/src/github.com/jmorganca/ollama                                                                                    0.0s
 => [ollama stage-2 4/5] COPY . .                                                                                                                              0.3s
 => ERROR [ollama stage-2 5/5] RUN /usr/local/go/bin/go generate ./... &&     /usr/local/go/bin/go build .                                                     0.8s
------
 > [ollama stage-2 5/5] RUN /usr/local/go/bin/go generate ./... &&     /usr/local/go/bin/go build .:
0.810 go: parsing $GOFLAGS: unknown flag -ldflags -w -s
------
failed to solve: process "/bin/sh -c /usr/local/go/bin/go generate ./... &&     /usr/local/go/bin/go build ." did not complete successfully: exit code: 1

Quick Workaround

  • To get a quick build, just override the params declared in the Dockerfile
  • Use the Infrastructure As Code file docker-compose.yaml to quickly build
    • At least that helped bypass the build problem
services:
  ollama:
    image: jmorganca/ollama
    build:
      context: .
      dockerfile: Dockerfile.build
      args:
        GOFLAGS: ""
    environment:
      MODELS_REGISTRY_SKIP_TLS_CHECK: true
    ports:
      - 11434:11434
<!-- gh-comment-id:1804999437 --> @marcellodesales commented on GitHub (Nov 10, 2023): * The build should be in a single command... * Yet, I can't get it to work because there might be some C compilation going on... * That's a lot of details for a new developer... # 🐳 Docker Compose Build * Local build with the compose above without passing any ARG param * Taking the defaults from Dockerfile ```console $ docker compose build [+] Building 3.4s (14/14) FINISHED docker:desktop-linux => [ollama internal] load build definition from Dockerfile.build 0.0s => => transferring dockerfile: 1.33kB 0.0s => [ollama internal] load .dockerignore 0.0s => => transferring context: 115B 0.0s => [ollama internal] load metadata for docker.io/nvidia/cuda-arm64:11.3.1-devel-centos8 1.8s => [ollama auth] nvidia/cuda-arm64:pull token for registry-1.docker.io 0.0s => [ollama base-arm64 1/3] FROM docker.io/nvidia/cuda-arm64:11.3.1-devel-centos8@sha256:26ae46571f0767212454c4135bf51f6235d0f4c189f21aab662bf24dd4ff1eff 0.0s => [ollama] https://dl.google.com/go/go1.21.3.linux-arm64.tar.gz 0.2s => [ollama internal] load build context 0.1s => => transferring context: 16.06kB 0.0s => CACHED [ollama base-arm64 2/3] RUN sed -i -e 's/mirrorlist/#mirrorlist/g' -e 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc 0.0s => CACHED [ollama base-arm64 3/3] RUN yum install -y git cmake 0.0s => CACHED [ollama stage-2 1/5] ADD https://dl.google.com/go/go1.21.3.linux-arm64.tar.gz /tmp/go1.21.3.tar.gz 0.0s => CACHED [ollama stage-2 2/5] RUN mkdir -p /usr/local && tar xz -C /usr/local </tmp/go1.21.3.tar.gz 0.0s => CACHED [ollama stage-2 3/5] WORKDIR /go/src/github.com/jmorganca/ollama 0.0s => [ollama stage-2 4/5] COPY . . 0.3s => ERROR [ollama stage-2 5/5] RUN /usr/local/go/bin/go generate ./... && /usr/local/go/bin/go build . 0.8s ------ > [ollama stage-2 5/5] RUN /usr/local/go/bin/go generate ./... && /usr/local/go/bin/go build .: 0.810 go: parsing $GOFLAGS: unknown flag -ldflags -w -s ------ failed to solve: process "/bin/sh -c /usr/local/go/bin/go generate ./... && /usr/local/go/bin/go build ." did not complete successfully: exit code: 1 ``` # Quick Workaround * To get a quick build, just override the params declared in the Dockerfile * Use the Infrastructure As Code file `docker-compose.yaml` to quickly build * At least that helped bypass the build problem ```yaml services: ollama: image: jmorganca/ollama build: context: . dockerfile: Dockerfile.build args: GOFLAGS: "" environment: MODELS_REGISTRY_SKIP_TLS_CHECK: true ports: - 11434:11434 ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#62328