---
# System prepended metadata

title: Dockerfiles(julab)

---

# Dockerfiles(julab)

```
# 選擇要安裝的作業系統(之前版本為Jupyter base)
FROM ubuntu:18.04
# 輸出可中文化
ENV PYTHONIOENCODING=utf-8
# 更新apt-get
RUN apt update -y  &&  apt upgrade -y && apt-get update
# python3-pip可安裝3.6以上，這邊設定為安裝3.8
RUN apt install -y python3.8 python3-pip
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
# Set Python version controler(安裝額外的服務，ex git)
RUN apt install -y vim curl git openjdk-8-jdk unixodbc unixodbc-dev \
    apt-transport-https \
    locales \
    && echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
    && locale-gen

# Add SQL Server ODBC Driver 17 for Ubuntu 18.04
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get install -y --allow-unauthenticated msodbcsql17
RUN ACCEPT_EULA=Y apt-get install -y --allow-unauthenticated mssql-tools
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
# Modify Section Name to MSSQL in /etc/odbcinst.ini
RUN sed -i 's/\[\([^]]*\)\]/[MSSQL]/g' /etc/odbcinst.ini

# 只是單純設定目錄，非系統地根目錄
WORKDIR /root

# Install cmake frome source(升版cmake，避免Sklearn有問題)
RUN apt purge cmake*
RUN apt-get install -y build-essential \
    wget \
    libssl-dev
RUN wget https://github.com/Kitware/CMake/releases/download/v3.18.2/cmake-3.18.2.tar.gz
RUN tar xf cmake-3.18.2.tar.gz
WORKDIR /root/cmake-3.18.2
RUN ./configure
RUN make
RUN make install
WORKDIR /root/nas
RUN rm -rf /root/cmake-3.18.2

RUN pip3 install jupyterlab
CMD ["jupyter","lab","--port","8888","--ip","0.0.0.0","--no-browser","--allow-root"]

RUN --runtime=nvidia -it -p 8888:8888 tensorflow/tensorflow:latest-gpu-py3
```

# 根目錄問題
1. docker image 先裝jupyter base會預測已jovyan作為使用者(user)因此權限非root，簡易改為子頡用法

|  種平建議   | 子頡建議  |
|  ----  | ----  |
| FROM jupyter  | FROM ubuntu|
| 使用者jovyan(user)  | 使用者為root在安裝jupyter |
2. jupyter/base-notebook的image，因為預設再開啟container時會給予一個jovyan的使用者權限，並無ROOT權限，因此無su權限則無法更新套件。
   * 簡單來說只能用此image起容器的既有套件，無法更新解決相容問題。
   * 建議可以使用ROOT權限進到112後，測試此image起容器後，能否更新套件。

# 安裝可以使用jupyter且包含tensorflow+GPU的docker image
1. 至portainer
    2. add container
    3. 於docker.io中輸入tensorflow/tensorflow:latest-gpu-jupyter
    4. RunTime=>選nvidia
    5. 參考：https://www.tensorflow.org/install/docker?hl=zh-tw
2. 完成設定後於終端機執行 nvidia-smi
    3. 確認是否有抓到nvidia的資源
3. 
