DEV Community

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

Posted on

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.

Top comments (1)

Collapse
 
sophialopez profile image
SophiaLopez

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