Docker Community Forums

Share and learn in the Docker community.

How to create docker container with arm64 binaries on Mac M1

I am using the following files:

docker-compose.yml

version: ‘3’
services:
postgres_db:
image: postgres:11.12
platform: linux/arm64
environment: # Set up postgres database name and password
POSTGRES_PASSWORD: password
POSTGRES_DB: stats
POSTGRES_USER: root
ports: # Set up ports exposed for other containers to connect to
- 5432:5432
networks:
- app-tier
volumes:
- ./postgres:/docker-entrypoint-initdb.d
python_app:
platform: linux/arm64
build:
context: .
dockerfile: Dockerfile
depends_on:
- postgres_db
ports:
- 8888:8888
networks:
- app-tier
command:
tail -f /dev/null
networks:
app-tier:
driver: bridge

Dockerfile

FROM continuumio/miniconda3
RUN apt-get update -y; apt-get upgrade -y; apt-get install -y vim-tiny vim-athena ssh
RUN apt-get install -y gcc musl-dev libpq-dev
COPY environment.yml environment.yml
RUN conda env create -f environment.yml
RUN echo “alias l=‘ls -lah’” >> ~/.bashrc
RUN conda install jupyter notebook
RUN pip install sqlalchemy psycopg2
ENV CONDA_EXE /opt/conda/bin/conda
ENV CONDA_PREFIX /opt/conda/envs/connect
ENV CONDA_PYTHON_EXE /opt/conda/bin/python
ENV CONDA_PROMPT_MODIFIER (connect)
ENV CONDA_DEFAULT_ENV connect stats
ENV PATH /opt/conda/envs/connect/bin:/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

As you notice I have used: platform: linux/arm64
I am running:
docker-compose up -d
docker-compose exec python_app bash

When I check the platform type I get:

uname -a

Linux f1df01d878ab 5.10.25-linuxkit #1 SMP PREEMPT Tue Mar 23 09:24:45 UTC 2021 x86_64 GNU/Linux

This was the problem, there is no arm64 version so the x64 version is being pulled.

1 Like