10
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Dockerでpyenv環境を構築

Last updated at Posted at 2019-04-30

0. はじめに

0-1. やること

Dockerでpyenvを構築します。
(Dockerならpython側仮想化して環境管理しなくても良くない?という突っ込みは無しで)

0-2. 動作検証環境

$ uname -a
Linux versapro-centos7 3.10.0-957.10.1.el7.x86_64 #1 SMP Mon Mar 18 15:06:45 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
$ docker --version
Docker version 18.09.5, build e8ff056

1. 手順

1-1. Dockerfileの作成

$ vim Dockerfile
Dockerfile
FROM centos:centos7
ENV HOME /root
ENV PYENV_ROOT $HOME/.pyenv
ENV PATH $PYENV_ROOT/bin:$PATH
RUN yum update -y && \
    yum install -y gcc zlib-devel bzip2 bzip2-devel readline readline-devel sqlite sqlite-devel openssl openssl-devel git libffi-devel && \
    curl https://bootstrap.pypa.io/get-pip.py | python && \
    git clone https://github.com/pyenv/pyenv.git ~/.pyenv && \
    echo 'eval "$(pyenv init -)"' >> ~/.bashrc

1-2. Dockerfileのbuild

$ docker build -t myimage:pyenv-20190430 .
(省略)
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE
myimage             pyenv-20190430      b5d3ac72fbc0        About a minute ago   541MB
centos              centos7             9f38484d220f        6 weeks ago          202MB

1-3. コンテナの起動&動作確認

$ docker run -it -d myimage:pyenv-20190430 --name pyenv -v /hogehoge/work:/pyenv
$ docker exec -it pyenv /bin/bash
[root@a353872d7f4e /]# pyenv --version
pyenv 1.2.11-11-g7dd5014
[root@a353872d7f4e /]# pyenv install --list
(省略)
[root@a353872d7f4e /]# pyenv install anaconda3-2019.03
Downloading Anaconda3-2019.03-Linux-x86_64.sh...
-> https://repo.continuum.io/archive/Anaconda3-2019.03-Linux-x86_64.sh
Installing Anaconda3-2019.03-Linux-x86_64...
Installed Anaconda3-2019.03-Linux-x86_64 to /root/.pyenv/versions/anaconda3-2019.03

[root@a353872d7f4e /]# pyenv versions
* system (set by /root/.pyenv/version)
  anaconda3-2019.03
[root@a353872d7f4e /]# mkdir -p /pyenv/anaconda3-2019.03
[root@a353872d7f4e /]# cd /pyenv/anaconda3-2019.03
[root@a353872d7f4e anaconda3-2019.03]# pyenv local anaconda3-2019.03
[root@a353872d7f4e anaconda3-2019.03]# python
Python 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@a353872d7f4e anaconda3-2019.03]# cat .python-version
anaconda3-2019.03
[root@a353872d7f4e anaconda3-2019.03]#

2. 参考

Docker上のCentOS7にpyenvをインストールしてpythonを管理する
 https://daichan.club/linux/78292
Dockerfileを書いてみる
 https://qiita.com/nl0_blu/items/1de829288db2670276e8

10
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?