There could be many reasons why this error occurs while working with containers:
- Using the wrong script header such as adding a space in between.
- Using some incompatible character encodings while writing the scripts
- Non-matching CPU architecture
- Missing file permissions
Here's an example of 3. Non-matching CPU architecture
:
$ docker version
Client:
Cloud integration: v1.0.31
Version: 20.10.23
API version: 1.41
Go version: go1.18.10
Git commit: 7155243
Built: Thu Jan 19 17:35:19 2023
OS/Arch: darwin/arm64
Context: desktop-linux
Experimental: true
Server: Docker Desktop 4.17.0 (99724)
Engine:
Version: 20.10.23
API version: 1.41 (minimum version 1.12)
Go version: go1.18.10
Git commit: 6051f14
Built: Thu Jan 19 17:31:28 2023
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.6.18
GitCommit: 2456e983eb9e37e47538f59ea18f2043c9a73640
runc:
Version: 1.1.4
GitCommit: v1.1.4-0-g5fd4c4d
docker-init:
Version: 0.19.0
GitCommit: de40ad0
It's the darwin/arm64
architecture of my laptop with the same Docker Engine installed:
#################################################
Executing in my current laptop
$ make image
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-X github.ibm.com/cloud-sre/version.Major= -X github.ibm.com/cloud-sre/version.Minor= -X github.ibm.com/cloud-sre/version.Build= -X github.ibm.com/cloud-sre/version.Timestamp=202303170049" -o osscatimporter ./cmd/osscatimporter
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-X github.ibm.com/cloud-sre/version.Major= -X github.ibm.com/cloud-sre/version.Minor= -X github.ibm.com/cloud-sre/version.Build= -X github.ibm.com/cloud-sre/version.Timestamp=202303170049" -o osscatpublisher ./cmd/osscatpublisher
jq: error: Could not open file metadata.json: No such file or directory
docker buildx build --platform=linux/amd64 -t api-osscatalog:latest .
[+] Building 153.2s (11/11) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 560B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker-virtual.artifactory.swg-devops.com/ubi8/ubi-minimal:8.7 34.2s
=> [auth] ubi8/ubi-minimal:pull token for docker-virtual.artifactory.swg-devops.com 0.0s
=> [1/5] FROM docker-virtual.artifactory.swg-devops.com/ubi8/ubi-minimal:8.7@sha256:65a240ad8bd3f2fff3e18a22ebadc40da0b145616231fc1e1625 91.3s
=> => resolve docker-virtual.artifactory.swg-devops.com/ubi8/ubi-minimal:8.7@sha256:65a240ad8bd3f2fff3e18a22ebadc40da0b145616231fc1e16251 0.0s
=> => sha256:0214a28336e387c66493c61bb394e86a18f3bea8dbc46de74a26f173ff553c89 429B / 429B 0.0s
=> => sha256:591670a5d6a620931ec51c1e7436300894f5320e76e9737f0366fc62114addd4 6.23kB / 6.23kB 0.0s
=> => sha256:d7c06497d5cebd39c0a4feb14981ec940b5c863e49903d320f630805b049cbff 39.28MB / 39.28MB 90.8s
=> => sha256:65a240ad8bd3f2fff3e18a22ebadc40da0b145616231fc1e16251f3c6dee087a 1.47kB / 1.47kB 0.0s
=> => extracting sha256:d7c06497d5cebd39c0a4feb14981ec940b5c863e49903d320f630805b049cbff 0.4s
=> [internal] load build context 0.2s
=> => transferring context: 23.77MB 0.2s
=> [2/5] RUN microdnf update && microdnf install procps ; 27.5s
=> [3/5] COPY osscatimporter / 0.0s
=> [4/5] COPY mailtemplate.tmpl / 0.0s
=> [5/5] COPY osscatpublisher / 0.0s
=> exporting to image 0.1s
=> => exporting layers 0.1s
=> => writing image sha256:8af2a24809c709c2ea80b1f3ed0c0d1dc1381c84219e0e779be43ab8542e8c0d 0.0s
=> => naming to docker.io/library/api-osscatalog:latest 0.0s
##############################
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
api-catalog latest 8af2a24809c7 9 seconds ago 140MB
######################################
$ docker image inspect api-catalog
"Architecture": "arm64",
"Os": "linux",
"Size": 148693891,
"VirtualSize": 148693891,
Produces an arm64
image
########################################
Issue after running instance in its log file shows:
$ kubectl -n api logs -f catimporter-rohit-gst45
exec /bin/sh: exec format error
Comment:
This usually happens when you’re working on projects on a system with ARM architecture, like with the new Apple M-series chipsets. When you push a code to your production environment, which is using an x86 system, it results in the “exec user process caused: exec format error”. This is because every piece of code when converted to the lower level of instructions is different for both ARM and x86. Docker detects the Apple M1 Pro platform as “linux/arm64/v8“.
################## SOLUTION ########################
1.
/cloud-sre/catalog/Makefile
Change:
docker build -t $(IMAGE_NAME):latest .
To:
docker buildx build --platform=linux/amd64 -t $(IMAGE_NAME):latest .
- But for the above to work, need to change the Dockerfile also
/cloud-sre/catalog/Dockerfile
Change:
FROM docker-virtual.artifactory.swg-devops.com/ubi8/ubi-minimal:8.7
To:
FROM --platform=linux/amd64 docker-virtual.artifactory.swg-devops.com/ubi8/ubi-minimal:8.7
#################### TEST ######################
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
Deleted all images.
#####################################
$ make image
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-X github.ibm.com/cloud-sre/version.Major= -X github.ibm.com/cloud-sre/version.Minor= -X github.ibm.com/cloud-sre/version.Build= -X github.ibm.com/cloud-sre/version.Timestamp=202303170049" -o osscatimporter ./cmd/osscatimporter
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-X github.ibm.com/cloud-sre/version.Major= -X github.ibm.com/cloud-sre/version.Minor= -X github.ibm.com/cloud-sre/version.Build= -X github.ibm.com/cloud-sre/version.Timestamp=202303170049" -o osscatpublisher ./cmd/osscatpublisher
jq: error: Could not open file metadata.json: No such file or directory
docker buildx build --platform=linux/amd64 -t api-osscatalog:latest .
[+] Building 153.2s (11/11) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 560B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker-virtual.artifactory.swg-devops.com/ubi8/ubi-minimal:8.7 34.2s
=> [auth] ubi8/ubi-minimal:pull token for docker-virtual.artifactory.swg-devops.com 0.0s
=> [1/5] FROM docker-virtual.artifactory.swg-devops.com/ubi8/ubi-minimal:8.7@sha256:65a240ad8bd3f2fff3e18a22ebadc40da0b145616231fc1e1625 91.3s
=> => resolve docker-virtual.artifactory.swg-devops.com/ubi8/ubi-minimal:8.7@sha256:65a240ad8bd3f2fff3e18a22ebadc40da0b145616231fc1e16251 0.0s
=> => sha256:0214a28336e387c66493c61bb394e86a18f3bea8dbc46de74a26f173ff553c89 429B / 429B 0.0s
=> => sha256:591670a5d6a620931ec51c1e7436300894f5320e76e9737f0366fc62114addd4 6.23kB / 6.23kB 0.0s
=> => sha256:d7c06497d5cebd39c0a4feb14981ec940b5c863e49903d320f630805b049cbff 39.28MB / 39.28MB 90.8s
=> => sha256:65a240ad8bd3f2fff3e18a22ebadc40da0b145616231fc1e16251f3c6dee087a 1.47kB / 1.47kB 0.0s
=> => extracting sha256:d7c06497d5cebd39c0a4feb14981ec940b5c863e49903d320f630805b049cbff 0.4s
=> [internal] load build context 0.2s
=> => transferring context: 23.77MB 0.2s
=> [2/5] RUN microdnf update && microdnf install procps ; 27.5s
=> [3/5] COPY osscatimporter / 0.0s
=> [4/5] COPY mailtemplate.tmpl / 0.0s
=> [5/5] COPY osscatpublisher / 0.0s
=> exporting to image 0.1s
=> => exporting layers 0.1s
=> => writing image sha256:8af2a24809c709c2ea80b1f3ed0c0d1dc1381c84219e0e779be43ab8542e8c0d 0.0s
=> => naming to docker.io/library/api-osscatalog:latest 0.0s
##############################################
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
api-catalog latest 8af2a24809c7 9 seconds ago 140MB
################################################
$ docker image inspect api-catalog:latest
"Architecture": "amd64",
"Os": "linux",
"Size": 140425582,
— Which I used to get in my old laptop always.
############################################
Now checking the log from the new instance:
$ kubectl -n api logs -f catimporter-rohit-9bzk9
INFO 19:53:29 osscatimporter Version: .. - 202303170049
INFO 19:53:29 sending *osscatimporter* Starting Run osscatimporter using the slack-webhook-url Slack webhook key.
Test COS connection passed: oss-rmc-data-test
Test COS connection passed: oss-rmc-emergency-test
AUDIT 19:53:30 Operating in read-only mode on all services and components found from all sources (with visibility=private and above)
INFO 19:53:30 Forcing -check-owner=true
INFO 19:53:30 Optional run action ENABLED: Services
INFO 19:53:30 Optional run action ENABLED: Tribes
INFO 19:53:30 Optional run action ENABLED: Environments
INFO 19:53:30 Optional run action ENABLED: Deployments
INFO 19:53:30 Optional run action ENABLED: Monitoring
INFO 19:53:30 Optional run action ENABLED: RMC
INFO 19:53:30 Optional run action ENABLED: RMC-Rescan
INFO 19:53:30 Optional run action DISABLED: Environments-Native
INFO 19:53:30 Optional run action DISABLED: ProductInfo-Parts
INFO 19:53:30 Optional run action DISABLED: ProductInfo-Parts-Refresh
INFO 19:53:30 Optional run action DISABLED: ProductInfo-ClearingHouse
INFO 19:53:30 Optional run action DISABLED: Dependencies-ClearingHouse
INFO 19:53:30 Optional run action DISABLED: ScorecardV1
INFO 19:53:30 Optional run action DISABLED: Doctor
INFO 19:53:30 Skip reloading Segment and Tribe Info from ScorecardV1
No Error