我在嘗試使用 go 應用程式在 docker 容器內執行 cmd
命令時遇到一些問題。
這是我得到的輸出:
golang-api | /bin/sh: ./server: not found golang-api exited with code 127
這是 dockerfile
from golang:1.18-alpine run apk add g++ && apk add make workdir /app copy go.mod go.sum ./ run go mod download copy . . run make build expose 8000 cmd ./server
這是負責建置指令的 makefile:
linux_amd64 = goos=linux goarch=amd64 cgo_enabled=1 go111module=on migrate: cd cmd/migrations/$(folder) && go run main.go build: cd cmd && $(linux_amd64) go build -a -v -tags musl -o server
還有 docker-compose.yml
version: '3.1' services: api: build: dockerfile: dockerfile context: . container_name: golang-api ports: - "8000:8000" restart: unless-stopped depends_on: - db environment: - postgres_url=$postgres_url db: image: postgres restart: always environment: postgres_user: postgres postgres_password: postgres ports: - '5432:5432'
完整輸出:
Building api Sending build context to Docker daemon 74.24kB Step 1/9 : FROM golang:1.18-alpine ---> 6078a5fce1f5 Step 2/9 : RUN apk add g++ && apk add make ---> Using cache ---> 2a85b9182b80 Step 3/9 : WORKDIR /app ---> Using cache ---> baf1e6b7047c Step 4/9 : COPY go.mod go.sum ./ ---> Using cache ---> 1f2d031bc1b0 Step 5/9 : RUN go mod download ---> Using cache ---> 471d6f24e6a9 Step 6/9 : COPY . . ---> eaa86ff7cb1b Step 7/9 : RUN make build ---> Running in d6ae6ce79222 cd cmd && GOOS=linux GOARCH=amd64 CGO_ENABLED=1 GO111MODULE=on go build -a -v -tags musl -o server internal/goos internal/goarch internal/race internal/unsafeheader internal/goexperiment runtime/internal/syscall internal/cpu sync/atomic runtime/internal/atomic internal/itoa math/bits internal/abi runtime/internal/math runtime/internal/sys unicode/utf8 unicode container/list crypto/internal/subtle crypto/subtle unicode/utf16 vendor/golang.org/x/crypto/cryptobyte/asn1 internal/nettrace vendor/golang.org/x/crypto/internal/subtle encoding github.com/mymachine/my-api/internal/controllers/dto github.com/mymachine/my-api/internal/controllers/helpers internal/bytealg math runtime internal/reflectlite sync internal/testlog internal/singleflight math/rand runtime/cgo errors sort internal/oserror strconv path vendor/golang.org/x/net/dns/dnsmessage io crypto/elliptic/internal/fiat syscall golang.org/x/text/internal/tag hash bytes strings hash/crc32 reflect crypto crypto/internal/randutil crypto/hmac crypto/rc4 net/http/internal/ascii vendor/golang.org/x/crypto/hkdf regexp/syntax github.com/jackc/chunkreader/v2 bufio crypto/elliptic/internal/nistec internal/syscall/unix time internal/syscall/execenv vendor/golang.org/x/text/transform golang.org/x/crypto/pbkdf2 golang.org/x/text/transform golang.org/x/text/runes golang.org/x/text/width regexp internal/poll io/fs context github.com/mymachine/my-api/internal/entities github.com/jackc/pgconn/internal/ctxwatch embed os github.com/jinzhu/inflection github.com/jinzhu/now internal/fmtsort encoding/binary crypto/ed25519/internal/edwards25519/field crypto/md5 crypto/sha512 crypto/cipher crypto/sha256 crypto/sha1 encoding/base64 fmt internal/godebug encoding/pem crypto/ed25519/internal/edwards25519 path/filepath vendor/golang.org/x/crypto/internal/poly1305 io/ioutil internal/intern vendor/golang.org/x/crypto/curve25519/internal/field vendor/golang.org/x/sys/cpu net/netip crypto/aes crypto/des vendor/golang.org/x/crypto/chacha20 github.com/jackc/pgio github.com/jackc/pgpassfile os/exec os/signal net vendor/golang.org/x/crypto/chacha20poly1305 math/big encoding/hex net/url compress/flate vendor/golang.org/x/crypto/curve25519 log vendor/golang.org/x/text/unicode/norm vendor/golang.org/x/text/unicode/bidi vendor/golang.org/x/net/http2/hpack mime mime/quotedprintable compress/gzip net/http/internal database/sql/driver github.com/mymachine/my-api/internal/pkg/errors encoding/json github.com/jackc/pgservicefile vendor/golang.org/x/text/secure/bidirule golang.org/x/text/internal/language database/sql golang.org/x/text/unicode/norm golang.org/x/text/unicode/bidi vendor/golang.org/x/net/idna os/user crypto/rand encoding/asn1 crypto/dsa crypto/elliptic crypto/ed25519 crypto/rsa github.com/jackc/pgproto3/v2 golang.org/x/text/internal/language/compact golang.org/x/text/secure/bidirule github.com/jackc/pgx/v4/internal/sanitize golang.org/x/text/language go/token vendor/golang.org/x/crypto/cryptobyte crypto/x509/pkix gorm.io/gorm/utils gorm.io/gorm/logger encoding/gob go/scanner golang.org/x/text/internal github.com/joho/godotenv crypto/ecdsa go/ast golang.org/x/text/cases github.com/joho/godotenv/autoload golang.org/x/text/secure/precis gorm.io/gorm/clause gorm.io/gorm/schema gorm.io/gorm net/textproto vendor/golang.org/x/net/http/httpproxy github.com/google/uuid crypto/x509 github.com/jackc/pgtype mime/multipart vendor/golang.org/x/net/http/httpguts crypto/tls gorm.io/gorm/migrator gorm.io/gorm/callbacks net/http/httptrace github.com/jackc/pgconn net/http github.com/jackc/pgconn/stmtcache github.com/jackc/pgx/v4 github.com/jackc/pgx/v4/stdlib gorm.io/driver/postgres github.com/mymachine/my-api/internal/infrastructure/repository github.com/mymachine/my-api/configs github.com/mymachine/my-api/internal/services github.com/mymachine/my-api/internal/services/transaction github.com/mymachine/my-api/internal/controllers/handlers/health github.com/gorilla/mux github.com/mymachine/my-api/internal/controllers/handlers/transaction github.com/mymachine/my-api/internal/router github.com/mymachine/my-api/cmd Removing intermediate container d6ae6ce79222 ---> 621aa6a266de Step 8/9 : EXPOSE 8000 ---> Running in 3cbd17d32c37 Removing intermediate container 3cbd17d32c37 ---> 754f71a7753e Step 9/9 : CMD ./server ---> Running in dfcdc8cd45ce Removing intermediate container dfcdc8cd45ce ---> 511dbf89a001 Successfully built 511dbf89a001 Successfully tagged my-api_api:latest Creating my-api_db_1 ... done Creating golang-api ... done Attaching to my-api_db_1, golang-api golang-api | /bin/sh: ./server: not found
正確答案
問題已解決。
不知何故,RUN cd cmd
指令似乎沒有在預期目錄中產生檔案。
嘗試使用 RUN go build cmd/main.go
而不是使用 makefile 有效,@paltaa 在評論中也指出了這一點。
以上是在 docker 容器上找不到可執行文件的詳細內容。更多資訊請關注PHP中文網其他相關文章!

OpenSSL,作為廣泛應用於安全通信的開源庫,提供了加密算法、密鑰和證書管理等功能。然而,其歷史版本中存在一些已知安全漏洞,其中一些危害極大。本文將重點介紹Debian系統中OpenSSL的常見漏洞及應對措施。 DebianOpenSSL已知漏洞:OpenSSL曾出現過多個嚴重漏洞,例如:心臟出血漏洞(CVE-2014-0160):該漏洞影響OpenSSL1.0.1至1.0.1f以及1.0.2至1.0.2beta版本。攻擊者可利用此漏洞未經授權讀取服務器上的敏感信息,包括加密密鑰等。

本文演示了創建模擬和存根進行單元測試。 它強調使用接口,提供模擬實現的示例,並討論最佳實踐,例如保持模擬集中並使用斷言庫。 文章

本文探討了GO的仿製藥自定義類型約束。 它詳細介紹了界面如何定義通用功能的最低類型要求,從而改善了類型的安全性和代碼可重複使用性。 本文還討論了局限性和最佳實踐

本文討論了GO的反思軟件包,用於運行時操作代碼,對序列化,通用編程等有益。它警告性能成本,例如較慢的執行和更高的內存使用,建議明智的使用和最佳

本文使用跟踪工具探討了GO應用程序執行流。 它討論了手冊和自動儀器技術,比較諸如Jaeger,Zipkin和Opentelemetry之類的工具,並突出顯示有效的數據可視化

本文討論了GO中使用表驅動的測試,該方法使用測試用例表來測試具有多個輸入和結果的功能。它突出了諸如提高的可讀性,降低重複,可伸縮性,一致性和A


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

記事本++7.3.1
好用且免費的程式碼編輯器

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。