Skip to content

Commit 0807931

Browse files
committed
make lighter alpine multi-stage build docker image, ~60% smaller
1 parent 7200a0b commit 0807931

File tree

1 file changed

+32
-157
lines changed

1 file changed

+32
-157
lines changed

Dockerfile

Lines changed: 32 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -1,159 +1,34 @@
1-
# Generated by Neurodocker and Reproenv.
1+
FROM python:3.10-alpine AS builder
22

3-
FROM neurodebian:bullseye
4-
ENV PATH="/opt/dcm2niix-v1.0.20220720/bin:$PATH"
5-
RUN apt-get update -qq \
6-
&& apt-get install -y -q --no-install-recommends \
7-
ca-certificates \
8-
cmake \
9-
g++ \
10-
gcc \
11-
git \
12-
make \
13-
pigz \
14-
zlib1g-dev \
15-
&& rm -rf /var/lib/apt/lists/* \
16-
&& git clone https://github.com/rordenlab/dcm2niix /tmp/dcm2niix \
17-
&& cd /tmp/dcm2niix \
18-
&& git fetch --tags \
19-
&& git checkout v1.0.20220720 \
20-
&& mkdir /tmp/dcm2niix/build \
21-
&& cd /tmp/dcm2niix/build \
22-
&& cmake -DZLIB_IMPLEMENTATION=Cloudflare -DUSE_JPEGLS=ON -DUSE_OPENJPEG=ON -DCMAKE_INSTALL_PREFIX:PATH=/opt/dcm2niix-v1.0.20220720 .. \
23-
&& make -j1 \
24-
&& make install \
25-
&& rm -rf /tmp/dcm2niix
26-
RUN apt-get update -qq \
27-
&& apt-get install -y -q --no-install-recommends \
28-
gcc \
29-
git \
30-
git-annex-standalone \
31-
libc-dev \
32-
liblzma-dev \
33-
netbase \
34-
pigz \
35-
&& rm -rf /var/lib/apt/lists/*
36-
COPY [".", \
37-
"/src/heudiconv"]
38-
ENV CONDA_DIR="/opt/miniconda-py39_4.12.0" \
39-
PATH="/opt/miniconda-py39_4.12.0/bin:$PATH"
40-
RUN apt-get update -qq \
41-
&& apt-get install -y -q --no-install-recommends \
42-
bzip2 \
43-
ca-certificates \
44-
curl \
45-
&& rm -rf /var/lib/apt/lists/* \
46-
# Install dependencies.
47-
&& export PATH="/opt/miniconda-py39_4.12.0/bin:$PATH" \
48-
&& echo "Downloading Miniconda installer ..." \
49-
&& conda_installer="/tmp/miniconda.sh" \
50-
&& curl -fsSL -o "$conda_installer" https://repo.continuum.io/miniconda/Miniconda3-py39_4.12.0-Linux-x86_64.sh \
51-
&& bash "$conda_installer" -b -p /opt/miniconda-py39_4.12.0 \
52-
&& rm -f "$conda_installer" \
53-
# Prefer packages in conda-forge
54-
&& conda config --system --prepend channels conda-forge \
55-
# Packages in lower-priority channels not considered if a package with the same
56-
# name exists in a higher priority channel. Can dramatically speed up installations.
57-
# Conda recommends this as a default
58-
# https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-channels.html
59-
&& conda config --set channel_priority strict \
60-
&& conda config --system --set auto_update_conda false \
61-
&& conda config --system --set show_channel_urls true \
62-
# Enable `conda activate`
63-
&& conda init bash \
64-
&& conda install -y --name base \
65-
"python=3.9" \
66-
"traits>=4.6.0" \
67-
"scipy" \
68-
"numpy" \
69-
"nomkl" \
70-
"pandas" \
71-
"gdcm" \
72-
&& bash -c "source activate base \
73-
&& python -m pip install --no-cache-dir --editable \
74-
"/src/heudiconv[all]"" \
75-
# Clean up
76-
&& sync && conda clean --all --yes && sync \
77-
&& rm -rf ~/.cache/pip/*
78-
ENTRYPOINT ["heudiconv"]
3+
RUN apk add bash \
4+
gcc \
5+
g++ \
6+
libc-dev \
7+
make \
8+
cmake \
9+
util-linux-dev \
10+
curl \
11+
git
12+
RUN pip install --no-cache-dir pylibjpeg-libjpeg traits==6.3.2
13+
14+
ARG DCM2NIIX_VERSION=v1.0.20240202
15+
RUN git clone https://github.com/rordenlab/dcm2niix /tmp/dcm2niix \
16+
&& cd /tmp/dcm2niix \
17+
&& git fetch --tags \
18+
&& git checkout $DCM2NIIX_VERSION \
19+
&& mkdir /tmp/dcm2niix/build \
20+
&& cd /tmp/dcm2niix/build \
21+
&& cmake -DZLIB_IMPLEMENTATION=Cloudflare -DUSE_JPEGLS=ON -DUSE_OPENJPEG=ON -DCMAKE_INSTALL_PREFIX:PATH=/usr/ .. \
22+
&& make -j1 \
23+
&& make install \
24+
&& rm -rf /tmp/dcm2niix
25+
26+
FROM python:3.10-alpine
27+
COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
28+
COPY --from=builder /usr/bin/dcm2niix /usr/bin/dcm2niix
7929

80-
# Save specification to JSON.
81-
RUN printf '{ \
82-
"pkg_manager": "apt", \
83-
"existing_users": [ \
84-
"root" \
85-
], \
86-
"instructions": [ \
87-
{ \
88-
"name": "from_", \
89-
"kwds": { \
90-
"base_image": "neurodebian:bullseye" \
91-
} \
92-
}, \
93-
{ \
94-
"name": "env", \
95-
"kwds": { \
96-
"PATH": "/opt/dcm2niix-v1.0.20220720/bin:$PATH" \
97-
} \
98-
}, \
99-
{ \
100-
"name": "run", \
101-
"kwds": { \
102-
"command": "apt-get update -qq\\napt-get install -y -q --no-install-recommends \\\\\\n ca-certificates \\\\\\n cmake \\\\\\n g++ \\\\\\n gcc \\\\\\n git \\\\\\n make \\\\\\n pigz \\\\\\n zlib1g-dev\\nrm -rf /var/lib/apt/lists/*\\ngit clone https://github.com/rordenlab/dcm2niix /tmp/dcm2niix\\ncd /tmp/dcm2niix\\ngit fetch --tags\\ngit checkout v1.0.20220720\\nmkdir /tmp/dcm2niix/build\\ncd /tmp/dcm2niix/build\\ncmake -DZLIB_IMPLEMENTATION=Cloudflare -DUSE_JPEGLS=ON -DUSE_OPENJPEG=ON -DCMAKE_INSTALL_PREFIX:PATH=/opt/dcm2niix-v1.0.20220720 ..\\nmake -j1\\nmake install\\nrm -rf /tmp/dcm2niix" \
103-
} \
104-
}, \
105-
{ \
106-
"name": "install", \
107-
"kwds": { \
108-
"pkgs": [ \
109-
"git", \
110-
"gcc", \
111-
"pigz", \
112-
"liblzma-dev", \
113-
"libc-dev", \
114-
"git-annex-standalone", \
115-
"netbase" \
116-
], \
117-
"opts": null \
118-
} \
119-
}, \
120-
{ \
121-
"name": "run", \
122-
"kwds": { \
123-
"command": "apt-get update -qq \\\\\\n && apt-get install -y -q --no-install-recommends \\\\\\n gcc \\\\\\n git \\\\\\n git-annex-standalone \\\\\\n libc-dev \\\\\\n liblzma-dev \\\\\\n netbase \\\\\\n pigz \\\\\\n && rm -rf /var/lib/apt/lists/*" \
124-
} \
125-
}, \
126-
{ \
127-
"name": "copy", \
128-
"kwds": { \
129-
"source": [ \
130-
".", \
131-
"/src/heudiconv" \
132-
], \
133-
"destination": "/src/heudiconv" \
134-
} \
135-
}, \
136-
{ \
137-
"name": "env", \
138-
"kwds": { \
139-
"CONDA_DIR": "/opt/miniconda-py39_4.12.0", \
140-
"PATH": "/opt/miniconda-py39_4.12.0/bin:$PATH" \
141-
} \
142-
}, \
143-
{ \
144-
"name": "run", \
145-
"kwds": { \
146-
"command": "apt-get update -qq\\napt-get install -y -q --no-install-recommends \\\\\\n bzip2 \\\\\\n ca-certificates \\\\\\n curl\\nrm -rf /var/lib/apt/lists/*\\n# Install dependencies.\\nexport PATH=\\"/opt/miniconda-py39_4.12.0/bin:$PATH\\"\\necho \\"Downloading Miniconda installer ...\\"\\nconda_installer=\\"/tmp/miniconda.sh\\"\\ncurl -fsSL -o \\"$conda_installer\\" https://repo.continuum.io/miniconda/Miniconda3-py39_4.12.0-Linux-x86_64.sh\\nbash \\"$conda_installer\\" -b -p /opt/miniconda-py39_4.12.0\\nrm -f \\"$conda_installer\\"\\n# Prefer packages in conda-forge\\nconda config --system --prepend channels conda-forge\\n# Packages in lower-priority channels not considered if a package with the same\\n# name exists in a higher priority channel. Can dramatically speed up installations.\\n# Conda recommends this as a default\\n# https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-channels.html\\nconda config --set channel_priority strict\\nconda config --system --set auto_update_conda false\\nconda config --system --set show_channel_urls true\\n# Enable `conda activate`\\nconda init bash\\nconda install -y --name base \\\\\\n \\"python=3.9\\" \\\\\\n \\"traits>=4.6.0\\" \\\\\\n \\"scipy\\" \\\\\\n \\"numpy\\" \\\\\\n \\"nomkl\\" \\\\\\n \\"pandas\\" \\\\\\n \\"gdcm\\"\\nbash -c \\"source activate base\\n python -m pip install --no-cache-dir --editable \\\\\\n \\"/src/heudiconv[all]\\"\\"\\n# Clean up\\nsync && conda clean --all --yes && sync\\nrm -rf ~/.cache/pip/*" \
147-
} \
148-
}, \
149-
{ \
150-
"name": "entrypoint", \
151-
"kwds": { \
152-
"args": [ \
153-
"heudiconv" \
154-
] \
155-
} \
156-
} \
157-
] \
158-
}' > /.reproenv.json
159-
# End saving to specification to JSON.
30+
RUN apk update && apk add --no-cache git git-annex pigz gcompat
31+
32+
RUN pip install --no-cache-dir heudiconv
33+
34+
ENTRYPOINT ["heudiconv"]

0 commit comments

Comments
 (0)