Executable file not found on docker container
I'm having some issues trying to run a cmd
command inside a docker container using a go application.
This is the output I get:
golang-api | /bin/sh: ./server: not found golang-api exited with code 127
This is 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
This is the makefile responsible for building the command:
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
Also 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'
Full output:
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
Correct answer
The problem has been solved.
Somehow, the RUN cd cmd
command doesn't seem to generate files in the expected directory.
Try using RUN go build cmd/main.go
instead of using makefile which works, @paltaa also pointed this out in the comments.
The above is the detailed content of Executable file not found on docker container. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Golang is better than Python in terms of performance and scalability. 1) Golang's compilation-type characteristics and efficient concurrency model make it perform well in high concurrency scenarios. 2) Python, as an interpreted language, executes slowly, but can optimize performance through tools such as Cython.

Golang is better than C in concurrency, while C is better than Golang in raw speed. 1) Golang achieves efficient concurrency through goroutine and channel, which is suitable for handling a large number of concurrent tasks. 2)C Through compiler optimization and standard library, it provides high performance close to hardware, suitable for applications that require extreme optimization.

Golang is suitable for rapid development and concurrent scenarios, and C is suitable for scenarios where extreme performance and low-level control are required. 1) Golang improves performance through garbage collection and concurrency mechanisms, and is suitable for high-concurrency Web service development. 2) C achieves the ultimate performance through manual memory management and compiler optimization, and is suitable for embedded system development.

Goimpactsdevelopmentpositivelythroughspeed,efficiency,andsimplicity.1)Speed:Gocompilesquicklyandrunsefficiently,idealforlargeprojects.2)Efficiency:Itscomprehensivestandardlibraryreducesexternaldependencies,enhancingdevelopmentefficiency.3)Simplicity:

Goisidealforbeginnersandsuitableforcloudandnetworkservicesduetoitssimplicity,efficiency,andconcurrencyfeatures.1)InstallGofromtheofficialwebsiteandverifywith'goversion'.2)Createandrunyourfirstprogramwith'gorunhello.go'.3)Exploreconcurrencyusinggorout

Golang and Python each have their own advantages: Golang is suitable for high performance and concurrent programming, while Python is suitable for data science and web development. Golang is known for its concurrency model and efficient performance, while Python is known for its concise syntax and rich library ecosystem.

C is more suitable for scenarios where direct control of hardware resources and high performance optimization is required, while Golang is more suitable for scenarios where rapid development and high concurrency processing are required. 1.C's advantage lies in its close to hardware characteristics and high optimization capabilities, which are suitable for high-performance needs such as game development. 2.Golang's advantage lies in its concise syntax and natural concurrency support, which is suitable for high concurrency service development.

The performance differences between Golang and C are mainly reflected in memory management, compilation optimization and runtime efficiency. 1) Golang's garbage collection mechanism is convenient but may affect performance, 2) C's manual memory management and compiler optimization are more efficient in recursive computing.
