-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Docker Slim Image #8640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Docker Slim Image #8640
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
510987d
Initial version of a slim Dockerfile
ericspod 983a833
Updates to clean up build
ericspod 566c2bc
Updates to produce slimmest Docker image possible
ericspod a07a861
Update to dockerfile with a possibly working config
ericspod 47b3ce3
Update
ericspod 463bb91
Merge remote-tracking branch 'origin/dev' into docker_slim
ericspod 23b7fb6
Merge remote-tracking branch 'origin/dev' into docker_slim
ericspod 5e7283f
Updates to various components, tests, and configs to pass tests withi…
ericspod 7942ab3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9887f81
DCO Remediation Commit for Eric Kerfoot <17726042+ericspod@users.nore…
ericspod 4e7d7c5
DCO Remediation Commit for Eric Kerfoot <eric.kerfoot@kcl.ac.uk>
ericspod cd88b32
Merge branch 'dev' into docker_slim
ericspod 3cdf717
Fix
ericspod 4d6e1bb
Cleanup
ericspod fc937d0
Experimenting with stages without CUDA toolkit
ericspod 90fb7ef
Nearly final version of dockerfile, all but 9 tests pass
ericspod 7421580
Merge branch 'dev' into docker_slim
ericspod 8aae06a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d83ab34
Fix for storage space issue with action images
ericspod 39ecb09
Missed one
ericspod 803fba4
Update Dockerfile.slim
ericspod ee7afe8
Missed another
ericspod 0438210
Merge branch 'dev' into docker_slim
ericspod 2a32409
Variable name fix
ericspod 95b2abc
Updates after a number of other PRs are integrated
ericspod 31eb818
Merge branch 'dev' into docker_slim
ericspod d216e6a
Remove onnxruntime restriction
ericspod 963315f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2b0ddc1
Merge branch 'dev' into docker_slim
ericspod ebdd268
Merge branch 'dev' into docker_slim
ericspod 84087b9
Adding documentation
ericspod 7f8addf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 55acac4
Comment updates
ericspod d5e3024
Merge branch 'docker_slim' of github.com:ericspod/MONAI into docker_slim
ericspod File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # Copyright (c) MONAI Consortium | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # This is a slimmed down version of the MONAI Docker image using a smaller base image and multi-stage building. Not all | ||
| # NVIDIA tools will be present but all libraries and compiled code are included. This image isn't provided through | ||
| # Dockerhub so users must build locally: `docker build -t monai_slim -f Dockerfile.slim .` | ||
| # Containers may require more shared memory, eg.: `docker run -ti --rm --gpus all --shm-size=10gb monai_slim /bin/bash` | ||
|
|
||
| ARG IMAGE=debian:12-slim | ||
|
|
||
| FROM ${IMAGE} AS build | ||
|
|
||
| ARG TORCH_CUDA_ARCH_LIST="7.5 8.0 8.6 8.9 9.0+PTX" | ||
|
|
||
| ENV DEBIAN_FRONTEND=noninteractive | ||
| ENV APT_INSTALL="apt install -y --no-install-recommends" | ||
|
|
||
| RUN apt update && apt upgrade -y && \ | ||
| ${APT_INSTALL} ca-certificates python3-pip python-is-python3 git wget libopenslide0 unzip python3-dev && \ | ||
| wget https://developer.download.nvidia.com/compute/cuda/repos/debian12/x86_64/cuda-keyring_1.1-1_all.deb && \ | ||
| dpkg -i cuda-keyring_1.1-1_all.deb && \ | ||
| apt update && \ | ||
| ${APT_INSTALL} cuda-toolkit-12 && \ | ||
| rm -rf /usr/lib/python*/EXTERNALLY-MANAGED /var/lib/apt/lists/* && \ | ||
| python -m pip install --upgrade --no-cache-dir --no-build-isolation pip | ||
|
|
||
| # TODO: remark for issue [revise the dockerfile](https://github.com/zarr-developers/numcodecs/issues/431) | ||
| RUN if [[ $(uname -m) =~ "aarch64" ]]; then \ | ||
| CFLAGS="-O3" DISABLE_NUMCODECS_SSE2=true DISABLE_NUMCODECS_AVX2=true python -m pip install numcodecs; \ | ||
| fi | ||
|
|
||
| # NGC Client | ||
| WORKDIR /opt/tools | ||
| ARG NGC_CLI_URI="https://ngc.nvidia.com/downloads/ngccli_linux.zip" | ||
| RUN wget -q ${NGC_CLI_URI} && unzip ngccli_linux.zip && chmod u+x ngc-cli/ngc && \ | ||
| find ngc-cli/ -type f -exec md5sum {} + | LC_ALL=C sort | md5sum -c ngc-cli.md5 && \ | ||
| rm -rf ngccli_linux.zip ngc-cli.md5 | ||
|
|
||
| WORKDIR /opt/monai | ||
|
|
||
| # copy relevant parts of repo | ||
| COPY requirements.txt requirements-min.txt requirements-dev.txt versioneer.py setup.py setup.cfg pyproject.toml ./ | ||
| COPY LICENSE CHANGELOG.md CODE_OF_CONDUCT.md CONTRIBUTING.md README.md MANIFEST.in runtests.sh ./ | ||
| COPY tests ./tests | ||
| COPY monai ./monai | ||
|
|
||
| # install full deps | ||
| RUN python -m pip install --no-cache-dir --no-build-isolation -r requirements-dev.txt | ||
|
|
||
| # compile ext | ||
| RUN CUDA_HOME=/usr/local/cuda FORCE_CUDA=1 USE_COMPILED=1 BUILD_MONAI=1 python setup.py develop | ||
|
|
||
| # recreate the image without the installed CUDA packages then copy the installed MONAI and Python directories | ||
| FROM ${IMAGE} AS build2 | ||
|
|
||
| ENV DEBIAN_FRONTEND=noninteractive | ||
| ENV APT_INSTALL="apt install -y --no-install-recommends" | ||
|
|
||
| RUN apt update && apt upgrade -y && \ | ||
| ${APT_INSTALL} ca-certificates python3-pip python-is-python3 git libopenslide0 && \ | ||
| apt clean && \ | ||
| rm -rf /usr/lib/python*/EXTERNALLY-MANAGED /var/lib/apt/lists/* && \ | ||
| python -m pip install --upgrade --no-cache-dir --no-build-isolation pip | ||
|
|
||
| COPY --from=build /opt/monai /opt/monai | ||
| COPY --from=build /opt/tools /opt/tools | ||
| ARG PYTHON_VERSION=3.11 | ||
| COPY --from=build /usr/local/lib/python${PYTHON_VERSION}/dist-packages /usr/local/lib/python${PYTHON_VERSION}/dist-packages | ||
| COPY --from=build /usr/local/bin /usr/local/bin | ||
|
|
||
| RUN rm -rf /opt/monai/build /opt/monai/monai.egg-info && \ | ||
| find /opt /usr/local/lib -type d -name __pycache__ -exec rm -rf {} + | ||
|
|
||
| # flatten all layers down to one | ||
| FROM ${IMAGE} | ||
| LABEL maintainer="monai.contact@gmail.com" | ||
|
|
||
| COPY --from=build2 / / | ||
|
|
||
| WORKDIR /opt/monai | ||
|
|
||
| ENV PATH=${PATH}:/opt/tools:/opt/tools/ngc-cli | ||
| ENV POLYGRAPHY_AUTOINSTALL_DEPS=1 | ||
| ENV CUDA_HOME=/usr/local/cuda | ||
| ENV BUILD_MONAI=1 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.