-
Notifications
You must be signed in to change notification settings - Fork 119
/
Dockerfile
97 lines (78 loc) · 2.84 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
## Start with ubuntu base
FROM ubuntu:20.04 AS build
ENV LANG=C.UTF-8
ARG PYTHON_VERSION=3.8
ARG CONDA_FILE=Miniconda3-py38_4.11.0-Linux-x86_64.sh
ENV DEBIAN_FRONTEND=noninteractive
# get install scripts into docker
COPY ./fastsurfer_env_gpu.yml /fastsurfer/fastsurfer_env_gpu.yml
COPY ./Docker/install_fs_pruned.sh /fastsurfer/install_fs_pruned.sh
# Install packages needed for build
RUN apt-get update && apt-get install -y --no-install-recommends \
wget \
git \
ca-certificates \
upx \
file && \
apt clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Install conda
RUN wget --no-check-certificate -qO ~/miniconda.sh https://repo.continuum.io/miniconda/$CONDA_FILE && \
chmod +x ~/miniconda.sh && \
~/miniconda.sh -b -p /opt/conda && \
rm ~/miniconda.sh
ENV PATH /opt/conda/bin:$PATH
# Install our dependencies
RUN conda env create -f /fastsurfer/fastsurfer_env_gpu.yml
# Install conda-pack:
RUN conda install -c conda-forge conda-pack
# Use conda-pack to create a standalone enviornment in /venv:
RUN conda-pack -n fastsurfer_gpu -o /tmp/env.tar && \
mkdir /venv && cd /venv && tar xf /tmp/env.tar && \
rm /tmp/env.tar
# Now that venv in a new location, fix up paths:
RUN /venv/bin/conda-unpack
ENV PATH /venv/bin:$PATH
# setup shell for install command below
RUN echo "source /venv/bin/activate" >> ~/.bashrc
SHELL ["/bin/bash", "--login", "-c"]
# install freesurfer and point to new python location
RUN /fastsurfer/install_fs_pruned.sh /opt --upx && \
rm /opt/freesurfer/bin/fspython && \
ln -s /venv/bin/python3 /opt/freesurfer/bin/fspython
# ========================================
# Here we create the smaller runtime image
# ========================================
FROM ubuntu:20.04 AS runtime
# Install required packages for freesurfer to run
RUN apt-get update && apt-get install -y --no-install-recommends \
tcsh \
time \
bc \
gawk \
libgomp1 && \
apt clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Add FreeSurfer Environment variables
ENV OS=Linux \
FS_OVERRIDE=0 \
FIX_VERTEX_AREA= \
SUBJECTS_DIR=/opt/freesurfer/subjects \
FSF_OUTPUT_FORMAT=nii.gz \
FREESURFER_HOME=/opt/freesurfer \
PYTHONUNBUFFERED=0 \
PATH=/venv/bin:/opt/freesurfer/bin:$PATH
# make sure we use bash and activate conda env
# (in case someone starts this interactively)
RUN echo "source /venv/bin/activate" >> ~/.bashrc
SHELL ["/bin/bash", "--login", "-c"]
# Copy venv fastsurfer and pruned freesurfer from builder
COPY --from=build /venv /venv
COPY --from=build /opt/freesurfer /opt/freesurfer
COPY . /fastsurfer/
# Set FastSurfer workdir and entrypoint
# the script entrypoint ensures that our conda env is active
WORKDIR "/fastsurfer"
ENV FASTSURFER_HOME=/fastsurfer
ENTRYPOINT ["./Docker/entrypoint.sh","./run_fastsurfer.sh"]
CMD ["--help"]