DockerでCentOS7上にPython開発環境を構築
Dockerfile
FROM centos:7
# configure root user
RUN echo 'root:root' | chpasswd
# configure development user
ARG user=me
RUN groupadd ${user} && \
useradd -g ${user} -m ${user} -s /bin/bash && \
echo "${user}:${user}" | chpasswd
# install essentials
RUN yum -y update && \
yum -y install vim less wget zip unzip make git && \
yum clean all
# install Python3 Development environment
ARG version=3.7.3
RUN yum -y install gcc bzip2-devel gdbm-devel libffi-devel \
libuuid-devel ncurses-devel openssl-devel readline-devel \
sqlite-devel tk-devel xz-devel zlib-devel && \
cd /tmp && \
curl -SL https://www.python.org/ftp/python/3.7.3/Python-${version}.tgz | tar xz && \
cd Python-${version} && \
./configure --enable-shared && \
make && \
make install && \
cd /tmp && \
rm -rf Python-${version} && \
sh -c "echo '/usr/local/lib' > /etc/ld.so.conf.d/custom_python3.conf" && \
ldconfig
イメージビルド
docker image build -f ./Dockerfile -t centos7:dev_python .
コンテナ生成&起動
docker container run -i -t --rm centos7:dev_python su - me
ホストをマウントする場合
docker container run -i -t --rm \
--mount type=bind,src=/Users/me/code,dst=/home/me/code \
centos7:dev_python su - me
DockerでUbuntu18.04上にPython開発環境を構築
Dockerfile
FROM ubuntu:18.04
# configure root user
RUN echo 'root:root' | chpasswd
# configure development user
ARG user=me
RUN groupadd ${user} && \
useradd -g ${user} -m ${user} -s /bin/bash && \
echo "${user}:${user}" | chpasswd
# install essentials
RUN apt update && apt -y upgrade && \
apt -y install vim less wget curl zip make git && \
apt clean
# install Python3 Development environment
RUN apt -y install python3.7 && \
ln -s /usr/bin/python3.7 /usr/bin/python3
イメージビルド
docker image build -f ./Dockerfile -t ubuntu18.04:dev_python .
コンテナ生成&起動
docker container run -i -t --rm ubuntu18.04:dev_python su - me
ホストをマウントする場合
docker container run -i -t --rm \
--mount type=bind,src=/Users/me/code,dst=/home/me/code \
ubuntu18.04:dev_python su - me