0
1

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 3 years have passed since last update.

RとPythonのDocker作業環境の構築

Posted at

前提

  • WSL2でdocker環境を構築していること
    (構築方法は以下で紹介)
  • コマンドプロンプトを管理者権限で開いて、WSL上で操作していること

WSLでdockerの環境構築

Dockerfile

以下のコードを、ローカルの作業ディレクトリ内に"Dockerfile"という名前で配置してください。

FROM ubuntu:18.04

# set timezone
RUN apt-get update \
    && apt-get install tzdata \
    && ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
RUN date

# install packages
RUN ["/bin/bash", "-c", "\
    apt-get update \
    && apt-get install -y \
    vim \
    build-essential \
    git curl llvm sqlite3 libssl-dev libbz2-dev \
    libreadline-dev libsqlite3-dev libncurses5-dev \
    libncursesw5-dev python-tk python3-tk tk-dev aria2 \
    lsb-release \
    python3.8 python3-pip \
    "]

# install pip package
RUN pip3 install pip --upgrade
RUN pip3 install pipenv
RUN python3 --version

RUN ["/bin/bash", "-c", "apt-get install -y software-properties-common"]
RUN apt-add-repository ppa:ansible/ansible -y
# install r
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
#RUN add-apt-repository 'deb https://cran.rstudio.com/bin/linux/ubuntu $(lsb_release -cs)-cran35/'
RUN add-apt-repository 'deb https://cran.rstudio.com/bin/linux/ubuntu bionic-cran35/'
RUN ["/bin/bash", "-c", "\
    apt-get update \
    && apt-get install -y r-base \
    "]
RUN Rscript --version
CMD ["/bin/bash", "-c"]

ビルドと実行

Dockerfileがあるディレクトリ内に、以下のシェルスクリプトを配置します。

#!/bin/bash

step1="" # build
step2=do # run

CONTAINER=好きなコンテナ名
TAG=好きなタグ名
NAME=${CONTAINER}:${TAG}

if [ $step1 ]; then
    sudo docker build -t $NAME .
fi

if [ $step2 ] ; then
    sudo docker run -itv `pwd`:/mnt/work $NAME /bin/bash
fi

step1=doとするとビルドを実行し、
step2=doとするとコンテナを起動します。

CONTAINERに好きなコンテナ名を、TAGに好きなタグ名を指定してください。

以下のコマンドでシェルを実行できます。(シェルスクリプトはhoge.shとします)

chmod u+x hoge.sh
./hoge.sh
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?