Docker Go tutorial

Hi I am new to Docker and I am trying to follow this tutorial at the following link: What will you learn in this module? | Docker Documentation and the step I am currently at is “Develop your app”.

I am trying to start the database engine using cockroachdb using the command shown on the tutorial:

docker run -d \
  --name roach \
  --hostname db \
  --network mynet \
  -p 26257:26257 \
  -p 8080:8080 \
  -v roach:/cockroach/cockroach-data \
  cockroachdb/cockroach:latest-v20.1 start-single-node \

However when I use this command I get the following error:

WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested

Then I tried a fix that was suggested upon searching it up, by adding the --platform flag

docker run -d \
  --name roach \
  --hostname db \
  --network mynet --platform linux/amd64 \
  -p 26257:26257 \
  -p 8080:8080 \
  -v roach:/cockroach/cockroach-data \
  cockroachdb/cockroach:latest start-single-node \
  --insecure

My current environment is an Apple M1 (apple silicon). Could I please have some suggestions/help on this issue?

Thank you

Hi :slight_smile:

The platform tag wont help you here.
The problem is that you are running on ARM64/v8 (Raspberry pi 4 maybe?)
But the image is only made for AMD64 cpus: Docker Hub

So, you need to find another image, or make it yourself :slight_smile:

On dockerhub you can sort by arch type:
https://hub.docker.com/search?q=CockroachDB&architecture=arm64

Maybe you can find an alternative to the image in the tutorial :slight_smile:

I have another question that is similar to this. I have built an image that is based on the golang:latest image on my M1 mac laptop. On docker hub there it says this golang:latest image is supported on arm64v8 architecture. I built the image successfully, however when running the image in a container using docker run --platform linux/arm64/v8 verification the following error message comes up:

standard_init_linux.go:219: exec user process caused: exec format error

I am currently trying to run the container on an M1 (apple silicon). I even used the platform tag in the build and run command to ensure it is using the arm64/v8 version of the golang:latest image because I am running on an M1 laptop. I dont really understand why the container doesn’t run successfully even though I am using the the image with the matching architecture of my host machine.

This is my Dockerfile:

FROM golang:latest


# Set default destination directory in the image
WORKDIR /app

# Copy services into the image
COPY ./ ./

# Download Go modules
RUN go mod download

# Run make to build the verification service
RUN make -C verification

EXPOSE 8080

# Run
CMD [ "verification/cmd/verification-service" ]

This is my build command:

docker build  --tag services:verification -f ./verification/cmd/Dockerfile --platform linux/arm64/v8 ./

This is my run command:

docker run --platform linux/arm64/v8 verification

Could I please have some help/suggestion on this issue?

Thank you

Maybe I miss the point, but this is what the --platform option is for on a machine that supports emulation. You set the platform to one of supported platforms and Docker Desktop for Mac will emulate the supported architecture. So you can use amd64 images on arm64 CPUs.

Did you get the same error message or something else? It worked for me on my Mac.

I guess you copied a binary which is not compatible with chosen platform (architecture). What is in

verification/cmd/verification-service

?

1 Like

You’re so right @rimelek, i just totally missed the fact that he wrote " Apple M1 ", where --platform should work, but this feature on M1 is “best effort” since there are some limitation regarding the emulation

@rimelek thanks it was because the binary for the wrong architecture was already present and my Dockerfile kept coping that over. Its fixed now, thank you!