Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't run docker container in macOS(M1), I got "exec /device-laptop-temp: exec format error" #1230

Open
jiekechoo opened this issue Oct 7, 2022 · 4 comments
Labels
question Further information is requested

Comments

@jiekechoo
Copy link
Member

I made a new Device Service from "https://www.youtube.com/watch?v=Qd1jWKdYWBw" in macOS(M1), "make docker" worked.

jiekechoo@jiekechoo device-laptop-temp % make docker
docker build \
		-f cmd/Dockerfile \
		--label "git_sha=79fa4f8752d73b4167d8946f6b3c92e95b86a39b" \
		-t edgexfoundry/device-laptop-temp:79fa4f8752d73b4167d8946f6b3c92e95b86a39b \
		-t edgexfoundry/device-laptop-temp:0.0.0-dev \
		.
[+] Building 2.1s (20/20) FINISHED                                                                                                                                                                                                 
 => [internal] load build definition from Dockerfile                                                                                                                                                                          0.0s
 => => transferring dockerfile: 37B                                                                                                                                                                                           0.0s
 => [internal] load .dockerignore                                                                                                                                                                                             0.0s
 => => transferring context: 2B                                                                                                                                                                                               0.0s
 => [internal] load metadata for docker.io/library/alpine:3.14                                                                                                                                                                1.4s
 => [internal] load metadata for docker.io/library/golang:1.17-alpine3.15                                                                                                                                                     1.6s
 => [internal] load build context                                                                                                                                                                                             0.0s
 => => transferring context: 4.90kB                                                                                                                                                                                           0.0s
 => [builder 1/8] FROM docker.io/library/golang:1.17-alpine3.15@sha256:543b0922baa147b87a568968462a9586e94b588426f51396a2666590cfba327a                                                                                       0.0s
 => [stage-1 1/7] FROM docker.io/library/alpine:3.14@sha256:1ab24b3b99320975cca71716a7475a65d263d0b6b604d9d14ce08f7a3f67595c                                                                                                  0.0s
 => CACHED [builder 2/8] WORKDIR /device-sdk-go                                                                                                                                                                               0.0s
 => CACHED [builder 3/8] RUN sed -e 's/dl-cdn[.]alpinelinux.org/nl.alpinelinux.org/g' -i~ /etc/apk/repositories                                                                                                               0.0s
 => CACHED [builder 4/8] RUN apk add --update --no-cache make git gcc libc-dev zeromq-dev libsodium-dev                                                                                                                       0.0s
 => CACHED [builder 5/8] COPY go.mod vendor* ./                                                                                                                                                                               0.0s
 => CACHED [builder 6/8] RUN [ ! -d "vendor" ] && go mod download all || echo "skipping..."                                                                                                                                   0.0s
 => [builder 7/8] COPY . .                                                                                                                                                                                                    0.0s
 => [builder 8/8] RUN make                                                                                                                                                                                                    0.3s
 => CACHED [stage-1 2/7] RUN sed -e 's/dl-cdn[.]alpinelinux.org/nl.alpinelinux.org/g' -i~ /etc/apk/repositories                                                                                                               0.0s 
 => CACHED [stage-1 3/7] RUN apk add --update --no-cache zeromq libc6-compat                                                                                                                                                  0.0s
 => CACHED [stage-1 4/7] COPY --from=builder /device-sdk-go/cmd/Attribution.txt /Attribution.txt                                                                                                                              0.0s
 => CACHED [stage-1 5/7] COPY --from=builder /device-sdk-go/cmd/device-laptop-temp /device-laptop-temp                                                                                                                        0.0s
 => CACHED [stage-1 6/7] COPY --from=builder /device-sdk-go/cmd/res/ /res                                                                                                                                                     0.0s
 => exporting to image                                                                                                                                                                                                        0.0s
 => => exporting layers                                                                                                                                                                                                       0.0s
 => => writing image sha256:a2d1a90395fecaa0b139d45d3c77029ad2ea04fdc773e945afecb3bf53de1db3                                                                                                                                  0.0s
 => => naming to docker.io/edgexfoundry/device-laptop-temp:79fa4f8752d73b4167d8946f6b3c92e95b86a39b                                                                                                                           0.0s
 => => naming to docker.io/edgexfoundry/device-laptop-temp:0.0.0-dev                                                                                                                                                          0.0s
jiekechoo@jiekechoo device-laptop-temp % uname -a
Darwin jiekechoo 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000 arm64
jiekechoo@jiekechoo device-laptop-temp % 

When I use " docker run ", something wrong:

jiekechoo@jiekechoo device-laptop-temp % docker run -it --rm edgexfoundry/device-laptop-temp:0.0.0-dev 
exec /device-laptop-temp: exec format error
jiekechoo@jiekechoo device-laptop-temp % 

I tried to add libc6-compat in Dockerfile, it worked in Raspberry Pi OS (64bit), but not worked in macOS(M1):

# Next image - Copy built Go binary into new workspace
FROM alpine:3.14
LABEL license='SPDX-License-Identifier: Apache-2.0' \
  copyright='Copyright (c) 2020: Intel'

RUN sed -e 's/dl-cdn[.]alpinelinux.org/nl.alpinelinux.org/g' -i~ /etc/apk/repositories

RUN apk add --update --no-cache zeromq libc6-compat

WORKDIR /
COPY --from=builder /device-sdk-go/cmd/Attribution.txt /Attribution.txt
COPY --from=builder /device-sdk-go/cmd/device-laptop-temp /device-laptop-temp
COPY --from=builder /device-sdk-go/cmd/res/ /res

EXPOSE 59999
@jiekechoo jiekechoo added the bug Something isn't working label Oct 7, 2022
@cloudxxx8 cloudxxx8 added question Further information is requested and removed bug Something isn't working labels Oct 7, 2022
@cloudxxx8
Copy link
Member

which branch or version are you using ?
are you able to compile and run the binary without docker?

@jiekechoo
Copy link
Member Author

I'm using v2.2.0.
compile and run in macOS worked find:

jiekechoo@jiekechoo cmd % 
jiekechoo@jiekechoo cmd % file device-laptop-temp 
device-laptop-temp: Mach-O 64-bit executable arm64
jiekechoo@jiekechoo cmd % ./device-laptop-temp 
level=INFO ts=2022-10-07T07:15:36.771234Z app=device-laptop-temp source=config.go:391 msg="Loaded service configuration from ./res/configuration.toml"
level=INFO ts=2022-10-07T07:15:36.7718Z app=device-laptop-temp source=config.go:551 msg="Using local configuration from file (0 envVars overrides applied)"
level=INFO ts=2022-10-07T07:15:36.773541Z app=device-laptop-temp source=httpserver.go:131 msg="Web server starting (localhost:59999)"
level=INFO ts=2022-10-07T07:15:36.77362Z app=device-laptop-temp source=messaging.go:69 msg="Setting options for secure MessageBus with AuthMode='usernamepassword' and SecretName='redisdb"
level=INFO ts=2022-10-07T07:15:36.774496Z app=device-laptop-temp source=messaging.go:97 msg="Connected to redis Message Bus @ redis://192.168.254.11:6379 publishing on 'edgex/events/device' prefix topic with AuthMode='usernamepassword'"
level=INFO ts=2022-10-07T07:15:36.774944Z app=device-laptop-temp source=init.go:134 msg="Check core-metadata service's status by ping..."
level=INFO ts=2022-10-07T07:15:36.83629Z app=device-laptop-temp source=init.go:60 msg="Service clients initialize successful."
level=INFO ts=2022-10-07T07:15:36.836375Z app=device-laptop-temp source=clients.go:124 msg="Using configuration for URL for 'core-metadata': http://192.168.254.11:59881"
level=INFO ts=2022-10-07T07:15:36.837819Z app=device-laptop-temp source=restrouter.go:55 msg="Registering v2 routes..."
level=INFO ts=2022-10-07T07:15:36.968354Z app=device-laptop-temp source=config.go:224 msg="Skipping use of Configuration Provider for custom configuration: Provider not available"
level=INFO ts=2022-10-07T07:15:36.96963Z app=device-laptop-temp source=config.go:391 msg="Loaded custom configuration from ./res/configuration.toml"
level=INFO ts=2022-10-07T07:15:36.969837Z app=device-laptop-temp source=config.go:283 msg="Loaded custom configuration from file (0 envVars overrides applied)"
level=INFO ts=2022-10-07T07:15:36.96988Z app=device-laptop-temp source=simpledriver.go:103 msg="Custom config is: {./res/off.jpg ./res/on.png {10}}"
level=WARN ts=2022-10-07T07:15:36.969904Z app=device-laptop-temp source=config.go:296 msg="unable to watch custom configuration for changes: Configuration Provider not enabled"
level=DEBUG ts=2022-10-07T07:15:36.969936Z app=device-laptop-temp source=service.go:212 msg="trying to find device service device-laptop-temp"
level=INFO ts=2022-10-07T07:15:37.005103Z app=device-laptop-temp source=service.go:230 msg="device service device-laptop-temp exists, updating it"
level=INFO ts=2022-10-07T07:15:37.033059Z app=device-laptop-temp source=profiles.go:54 msg="Loading pre-defined profiles from /Users/jiekechoo/devel/edgex/device-laptop-temp/cmd/res/profiles"
level=INFO ts=2022-10-07T07:15:37.068824Z app=device-laptop-temp source=profiles.go:88 msg="Profile Laptop-Device-Profile exists, using the existing one"
level=INFO ts=2022-10-07T07:15:37.06891Z app=device-laptop-temp source=devices.go:49 msg="Loading pre-defined devices from /Users/jiekechoo/devel/edgex/device-laptop-temp/cmd/res/devices"
level=INFO ts=2022-10-07T07:15:37.069187Z app=device-laptop-temp source=devices.go:85 msg="Device Laptop-Device exists, using the existing one"
level=INFO ts=2022-10-07T07:15:37.069203Z app=device-laptop-temp source=autodiscovery.go:33 msg="AutoDiscovery stopped: disabled by configuration"
level=INFO ts=2022-10-07T07:15:37.069223Z app=device-laptop-temp source=message.go:50 msg="Service dependencies resolved..."
level=INFO ts=2022-10-07T07:15:37.069227Z app=device-laptop-temp source=message.go:51 msg="Starting device-laptop-temp 0.0.0 "
level=INFO ts=2022-10-07T07:15:37.06923Z app=device-laptop-temp source=message.go:55 msg="device simple started"
level=INFO ts=2022-10-07T07:15:37.069233Z app=device-laptop-temp source=message.go:58 msg="Service started in: 298.482083ms"
level=DEBUG ts=2022-10-07T07:15:42.070256Z app=device-laptop-temp source=executor.go:52 msg="AutoEvent - reading temperature"

@cloudxxx8
Copy link
Member

Please check whether the /device-laptop-temp in the docker container can be exectuted as the binary file you built.
Use docker cp to retrieve it

@jiekechoo
Copy link
Member Author

Please check whether the /device-laptop-temp in the docker container can be exectuted as the binary file you built.
Use docker cp to retrieve it

Yes, I tried it, but it can't run in container.

Does anyone run device service in docker on macOS?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants