Create Dockerfile

#1
by LudwigO - opened
Files changed (1) hide show
  1. Dockerfile +169 -0
Dockerfile ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM nvidia/cuda:11.3.1-base-ubuntu20.04
2
+
3
+ ENV DEBIAN_FRONTEND=noninteractive \
4
+ TZ=Europe/Paris
5
+
6
+ # Remove any third-party apt sources to avoid issues with expiring keys.
7
+ # Install some basic utilities
8
+ RUN rm -f /etc/apt/sources.list.d/*.list && \
9
+ apt-get update && apt-get install -y --no-install-recommends \
10
+ curl \
11
+ ca-certificates \
12
+ sudo \
13
+ git \
14
+ wget \
15
+ procps \
16
+ git-lfs \
17
+ zip \
18
+ unzip \
19
+ htop \
20
+ vim \
21
+ nano \
22
+ bzip2 \
23
+ libx11-6 \
24
+ build-essential \
25
+ libsndfile-dev \
26
+ software-properties-common \
27
+ && rm -rf /var/lib/apt/lists/*
28
+
29
+ RUN add-apt-repository ppa:flexiondotorg/nvtop && \
30
+ apt-get upgrade -y && \
31
+ apt-get install -y --no-install-recommends nvtop
32
+
33
+ RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
34
+ apt-get install -y nodejs && \
35
+ npm install -g configurable-http-proxy
36
+
37
+ # Create a working directory
38
+ WORKDIR /app
39
+
40
+ # Create a non-root user and switch to it
41
+ RUN adduser --disabled-password --gecos '' --shell /bin/bash user \
42
+ && chown -R user:user /app
43
+ RUN echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-user
44
+ USER user
45
+
46
+ # All users can use /home/user as their home directory
47
+ ENV HOME=/home/user
48
+ RUN mkdir $HOME/.cache $HOME/.config \
49
+ && chmod -R 777 $HOME
50
+
51
+ # Set up the Conda environment
52
+ ENV CONDA_AUTO_UPDATE_CONDA=false \
53
+ PATH=$HOME/miniconda/bin:$PATH
54
+ RUN curl -sLo ~/miniconda.sh https://repo.continuum.io/miniconda/Miniconda3-py39_4.10.3-Linux-x86_64.sh \
55
+ && chmod +x ~/miniconda.sh \
56
+ && ~/miniconda.sh -b -p ~/miniconda \
57
+ && rm ~/miniconda.sh \
58
+ && conda clean -ya
59
+
60
+ WORKDIR $HOME/app
61
+
62
+ #######################################
63
+ # Start root user section
64
+ #######################################
65
+
66
+ USER root
67
+
68
+ # User Debian packages
69
+ ## Security warning : Potential user code executed as root (build time)
70
+ RUN --mount=target=/root/packages.txt,source=packages.txt \
71
+ apt-get update && \
72
+ xargs -r -a /root/packages.txt apt-get install -y --no-install-recommends \
73
+ && rm -rf /var/lib/apt/lists/*
74
+
75
+ RUN --mount=target=/root/on_startup.sh,source=on_startup.sh,readwrite \
76
+ bash /root/on_startup.sh
77
+
78
+ RUN mkdir /data && chown user:user /data
79
+
80
+ #######################################
81
+ # End root user section
82
+ #######################################
83
+
84
+ USER user
85
+
86
+ # Pull chemprop from github
87
+ RUN git clone https://github.com/chemprop/chemprop.git
88
+ RUN cd chemprop
89
+
90
+ # build an empty conda environment with appropriate Python version
91
+ RUN conda create --name chemprop_env python=3.11*
92
+
93
+ SHELL ["conda", "run", "--no-capture-output", "-n", "chemprop_env", "/bin/bash", "-c"]
94
+
95
+
96
+
97
+ # Python packages
98
+ RUN --mount=target=requirements.txt,source=requirements.txt \
99
+ pip install --no-cache-dir --upgrade -r requirements.txt
100
+
101
+
102
+
103
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
104
+ COPY --chown=user . $HOME/app
105
+
106
+ RUN chmod +x start_server.sh
107
+
108
+ COPY --chown=user login.html /home/user/miniconda/lib/python3.9/site-packages/jupyter_server/templates/login.html
109
+
110
+ ENV PYTHONUNBUFFERED=1 \
111
+ GRADIO_ALLOW_FLAGGING=never \
112
+ GRADIO_NUM_PORTS=1 \
113
+ GRADIO_SERVER_NAME=0.0.0.0 \
114
+ GRADIO_THEME=huggingface \
115
+ SYSTEM=spaces \
116
+ SHELL=/bin/bash
117
+
118
+ CMD ["./start_server.sh"]
119
+ ####################################################### FROM CHEMPROP DOCKERFILE ##########################################################
120
+ # Dockerfile
121
+ #
122
+ # Builds a Docker image containing Chemprop and its required dependencies.
123
+ #
124
+ # Build this image with:
125
+ # git clone https://github.com/chemprop/chemprop.git
126
+ # cd chemprop
127
+ # docker build --tag=chemprop:latest .
128
+ #
129
+ # Run the built image with:
130
+ # docker run --name chemprop_container -it chemprop:latest
131
+ #
132
+ # Note:
133
+ # This image only runs on CPU - we do not provide a Dockerfile
134
+ # for GPU use (see installation documentation).
135
+
136
+ # Parent Image
137
+ #FROM continuumio/miniconda3:latest
138
+
139
+ # Install libxrender1 (required by RDKit) and then clean up
140
+ #RUN apt-get update && \
141
+ # apt-get install -y \
142
+ # libxrender1 && \
143
+ # apt-get autoremove -y && \
144
+ # apt-get clean -y
145
+
146
+ #WORKDIR /opt/chemprop
147
+
148
+ # build an empty conda environment with appropriate Python version
149
+ RUN conda create --name chemprop_env python=3.11*
150
+
151
+ # This runs all subsequent commands inside the chemprop_env conda environment
152
+ #
153
+ # Analogous to just activating the environment, which we can't actually do here
154
+ # since that requires running conda init and restarting the shell (not possible
155
+ # in a Dockerfile build script)
156
+ SHELL ["conda", "run", "--no-capture-output", "-n", "chemprop_env", "/bin/bash", "-c"]
157
+
158
+ # Follow the installation instructions then clear the cache
159
+ ADD chemprop chemprop
160
+ ENV PYTHONPATH /opt/chemprop
161
+ ADD LICENSE.txt pyproject.toml README.md ./
162
+ RUN conda install pytorch cpuonly -c pytorch && \
163
+ conda clean --all --yes && \
164
+ python -m pip install . && \
165
+ python -m pip cache purge
166
+
167
+ # when running this image, open an interactive bash terminal inside the conda environment
168
+ RUN echo "conda activate chemprop_env" > ~/.bashrc
169
+ ENTRYPOINT ["/bin/bash", "--login"]