# Docker

Standard Docker that contains most of the libraries and setups needed for ML research.
Feel free to comment out nginx component out if not needed.

# Dockerfile

FROM ubuntu:22.04 as apps
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update -y
RUN apt-get -y update && apt-get -y install nginx tmux wget
RUN apt-get -y install locales
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
ENV LANG en_US.UTF-8  
ENV LANGUAGE en_US:en  
ENV LC_ALL en_US.UTF-8  

RUN apt-get update -y
RUN apt-get install --no-install-recommends ruby-full build-essential zlib1g-dev -y 
RUN apt-get install imagemagick apache2-utils -y
RUN apt-get clean && rm -rf /var/lib/apt/lists/
RUN gem install jekyll bundler
RUN apt-get update && apt-get install -y curl sudo

ENV CONDA_DIR /opt/conda
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-py311_24.3.0-0-Linux-x86_64.sh -O ~/anaconda.sh && \
     /bin/bash ~/anaconda.sh -b -p /opt/conda
ENV PATH=$CONDA_DIR/bin:$PATH
RUN conda update -n base -c defaults conda -y
RUN conda install gunicorn -y
COPY environment.yml .
RUN conda env create -f environment.yml
ENV PATH /opt/conda/envs/vishal/bin:$PATH

RUN apt-get update && apt-get install -y ca-certificates curl gnupg
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
ENV NODE_MAJOR=20
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN apt-get update && apt-get install nodejs -y

RUN npx next telemetry disable

ENV DOCKER_ENV="Custom Environment which can be overridden on-the-fly in live settings without rebuilding"

WORKDIR /apps
EXPOSE 80/tcp

COPY folder1 /apps/folder1
WORKDIR /apps/folder1
RUN bundle install --quiet

COPY folder2/*package*.json /apps/folder2/
WORKDIR /apps/folder2
RUN npm i --quiet --no-update-notifier --no-fund --no-audit

WORKDIR /apps
EXPOSE 5000
# Comment out if not using nginx policy files
COPY default /etc/nginx/sites-available/default

COPY boot.sh /apps/boot.sh
COPY Dockerfile /apps/Dockerfile
ENTRYPOINT /bin/bash -x boot.sh && nginx -g 'daemon off;'
# If not using nginx
# ENTRYPOINT /bin/bash -x boot.sh 

# Docker Boot

pushd /apps/folder1
gunicorn -b :5000 \
    pythonfile:app \
    --workers=3 \
    --threads=3 \
    --worker-connections=1000 \
    --access-logfile - \
    --error-logfile - &
popd

pushd /apps/folder2
# Can use other codes running in parallel as code/research demands here
popd

# Build and Execution

time docker build -f Dockerfile  \
    --platform=linux/amd64 . \
    -t <container-registery>.azurecr.io/repository:<tag> \
    -t <container-registery>.azurecr.io/repository:latest
docker run -it \
    -p <external-port>:<internal-port>> \
    <container-registery>.azurecr.io/repository:latest