Dockerfile@M1 Mac突貫工事

最初のFROM --platform=linux/amd64 ubuntu:latestに集約されますが、M1 MacでDockerfileを単にbuildしようとすると、minicondaのインストールでエラーが出ました。
というわけでとりま突貫のdockerfileです。
拡張子なしでcurrent directoryに保存して、下記コマンドでdocker imageにbuildできます。

docker build -t `image_name` .

こちらがdockerfileです。

# M1 MacでUbuntuコンテナを作る時の注意
# https://qiita.com/silloi/items/739699337b9bf4883b3e
FROM --platform=linux/amd64 ubuntu:latest

# update
RUN apt-get -y update && apt-get install -y \
libsm6 \
libxext6 \
libxrender-dev \
libglib2.0-0 \
sudo \
wget \
unzip \
vim

#install miniconda3
WORKDIR /opt
# download miniconda package and install miniconda
# archive -> https://docs.conda.io/en/latest/miniconda.html
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
RUN bash /opt/Miniconda3-latest-Linux-x86_64.sh -b -p /opt/miniconda3
RUN rm -f Miniconda3-latest-Linux-x86_64.sh
# set path
ENV PATH /opt/miniconda3/bin:$PATH

# conda create
RUN conda create -n pymol python=3.7

# install conda package
SHELL ["conda", "run", "-n", "pymol", "/bin/bash", "-c"]
# https://qiita.com/kimisyo/items/66db9c9db94751b8572b

RUN command conda config --append channels conda-forge
RUN conda install -c conda-forge rdkit -y
RUN conda install -c conda-forge pymol-open-source -y
RUN conda install plotly
RUN conda install -c conda-forge nodejs jupyterlab
RUN conda install -c conda-forge py3dmol

WORKDIR /
RUN mkdir /work
WORKDIR /

RUN conda init



# かめさんのdocker image_name
# datascientistus/ds-python-env

# ubuntuというdocker imageをbuild
# docker build -t ubuntu . 

# 最初からbuildするなら--no-cache
# docker build -t ubuntu . --no-cache

# sbddというcontainerをubuntuというimageからcreateしてbashでrun
# docker run -it -v ~/Documents/Linux:/work --name sbdd ubuntu bash

私の環境では最後のRUN conda initがないと、コンテナでcondaコマンドを使う時に下記のエラーが出ました。

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.

かめさんのUdemy講座では下記のscriptを追加して、bashを起動せずにhost側のlocalhost:8888からコンテナにアクセスしてました。

# execute jupyterlab as a default command
CMD ["jupyter", "lab", "--ip=0.0.0.0", "--allow-root", "--LabApp.token=''"]

# ubuntuというimageからsbddというコンテナをポート8888に繋いでrun
# docker run -v ~/Documents/Linux:/work  -p 8888:8888 -it --name sbdd ubuntu

この方法だとPCの再起動なんかでやむを得ずコンテナを止めてしまった時に、restartしてもlocalhost:8888からjupyterに入れませんでした。   気になるので問い合わせ中です。