Docker + DataScience

Thiago Soares
Docker: Um canivete suíço
2 min readMar 29, 2020

Docker para estudo de DataScience

DataSciense é um caminho sem volta pra mim, ou o novo petróleo! Fiz um curso muito bom de DataSciense e precisava estudar, mas não queria ficar instalando nada no meu notebook, então criei um repositório (https://github.com/tsoarescruz/DataCamp), com o Docker para poder fazer tudo de maneira simples e rápida.
Essa demonstração não incluí os notebooks e sim a implementação do Docker + Pandas + Anaconda + Jupyter.

Dockerfile:

FROM debian:latest

ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
ENV PATH /opt/conda/bin:$PATH

RUN apt-get update — fix-missing && apt-get install -y wget bzip2 ca-certificates \
libglib2.0–0 libxext6 libsm6 libxrender1 build-essential libssl-dev apt-utils \
curl && apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/*

RUN apt-get install -y curl grep sed dpkg && \
TINI_VERSION=`curl https://github.com/krallin/tini/releases/latest | grep -o “/v.*\”” | sed ‘s:^..\(.*\).$:\1:’` && \
curl -L “https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini_${TINI_VERSION}.deb" > tini.deb && \
dpkg -i tini.deb && \
rm tini.deb && \
apt-get clean

RUN wget https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh -O ~/anaconda.sh && \
/bin/bash ~/anaconda.sh -b -p /opt/conda && \
rm ~/anaconda.sh && \
ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
echo “. /opt/conda/etc/profile.d/conda.sh” >> ~/.bashrc && \
echo “conda activate base” >> ~/.bashrc

# Install pandas and upgrade pip and pyzmq

RUN pip install — upgrade pip
RUN pip install pandas
RUN pip install jupyter_contrib_nbextensions
RUN pip install — upgrade — force-reinstall pyzmq

# Mkdir app
RUN mkdir -p /home/app/

# Mkdir notebooks
RUN mkdir /opt/notebooks/

ADD . /opt/notebooks/

# Workdir notebooks
WORKDIR /opt/notebooks/

# Create user and group
RUN groupadd — gid 9999 app && \
useradd — uid 9999 — gid app app && \
chown -R app:app /home/app

RUN export PATH=/home/app/anaconda/bin:$PATH

EXPOSE 80 8888 8001

ENTRYPOINT [ “/usr/bin/tini”, “ — “ ]
CMD [ “/bin/bash”]

Build Dockerfile

docker build -t <image_name> .

Comando para iniciar o container com o Jupyter/pandas:

docker run -it -p 8888:8888 <imagem_name> /bin/bash -c "/opt/conda/bin/conda install jupyter pandas -y && /opt/conda/bin/jupyter notebook --notebook-dir=/opt/notebooks/ --ip='0.0.0.0' --port=8888 --no-browser --allow-root"

Abrir a saída do terminal no Browser, como o exemplo:

http://127.0.0.1:8888/?token=3d4e3c6f286b3e84efd38597a156dc1f035cfe11a9dc13f7

--

--