DEV Community

Hui`s Journal of Technology
Hui`s Journal of Technology

Posted on

3 2

Create docker image on your new MacBook Pro M1 version

I just changed my major work laptop to the new MacBook Pro M1 Pro version. I really love this new machine as it can work almost 10 hours without charging. However, as a developer and product manager, sometimes I feel annoyed because of the new architecture.

Recently I work on a open source project and I am trying to optimize the developer experience of this project to allow developers use docker image to execute the CLI, which avoids installing lots of dependencies on developers` laptop.

However, I found I need create a separate Dockerfile for my new Apple M1 Mac.

First, the x86_64 base image cannot be used anymore, I have to explicitly use arm64 version base image.


FROM --platform=arm64 ubuntu

Secondly, I have to add lots of IF statements to detect the architecture of the host.


arch=
uname -m
if [[ "${arch}" == "arm64" ]]; then
if [[ "$OSTYPE" == "darwin"* ]]; then
//add your logic here
fi
if [[ "$OSTYPE" == "linux"* ]]; then
//add your logic here
fi
fi

Finally, I have to create arm64 version Dockerfile and build image with this file on my M1 Mac.


docker build -t xxx . -f Dockerfile.arm64

It will be great if you can give me a better solution.

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (1)

Collapse
 
sophialopez profile image
SophiaLopez

How do I run a Docker image on a Mac? Mohini mantra attract anyone by photo

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay