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.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

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

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

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

Okay