Skip to content
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

use multi-stage build to minimize size of Docker image #346

Merged
merged 1 commit into from
Sep 7, 2020

Conversation

kaczmarj
Copy link
Contributor

@kaczmarj kaczmarj commented Sep 4, 2020

The changes in this commit reduce the Docker image size from >1 GB to 205 MB. Docker multi-stage builds were used to achieve this. In the first stage, the core ta-lib library is compiled, and the Python ta-lib package is installed. Then, in the second stage, the compiled core ta-lib library and the Python wheel files are copied over and installed. The second stage also uses the python:VERSION-slim Docker image, which is much smaller than the python:VERSION image, because it does not include any compilers or other software not necessary at runtime.

The build and run procedure is unchanged. Use docker build --tag ta-lib . to build and docker run --rm -it ta-lib bash to run.

Another change introduced by the commit is the option of skipping testing during image building. By default, testing is not skipped, but it can be skipped with docker build --tag ts-lib --build-arg RUN_TESTS=0 ..

I uploaded a built image to https://hub.docker.com/r/kaczmarj/ta-lib: docker pull kaczmarj/ta-lib

The changes in this commit reduce the Docker image size from >1 GB to 205 MB. Docker multi-stage builds were used to achieve this. In the first stage, the core ta-lib library is compiled, and the Python ta-lib package is installed. Then, in the second stage, the compiled core ta-lib library and the Python wheel files are copied over and installed. The second stage also uses the `python:VERSION-slim` Docker image, which is much smaller than the `python:VERSION` image, because it does not include any compilers or other software not necessary at runtime.

The build and run procedure is unchanged. Use `docker build --tag ta-lib .` to build and `docker run --rm -it ta-lib bash` to run.

Another change introduced by the commit is the option of skipping testing during image building. By default, testing is not skipped, but it can be skipped with `docker uild --tag ts-lib --build-arg RUN_TESTS=0 .`.
COPY . .
RUN python -m pip install -e . \
&& python -c 'import numpy, talib; close = numpy.random.random(100); output = talib.SMA(close); print(output)' \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this line for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The python -m pip install -e . command installs the ta-lib python package. The next line came from the original Dockerfile and is basically a test that the package can be imported and can run talib.SMA.

@mrjbq7 mrjbq7 merged commit f36444d into TA-Lib:master Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants