Dockerising an Application for DataCosmos
Application providers must provide a Docker image for their application to be deployed in DataCosmos.
To build a docker image for your application in DataCosmos, use the following Dockerfile
as a guide. Be aware that your application may require additional steps, for example, to copy
in extra files outside of the repository or to install extra dependencies which cannot be
installed with pip.
FROM python3:10
WORKDIR /app
COPY requirements.txt /app/requirements.txt
RUN python -m pip install -r /app/requirements.txt
COPY . /app/
ENTRYPOINT ["python", "app/main.py"]
It assumes your application is structured as follows:
- application's requirements are given in a
requirements.txtsuitable forpip - application is invoked via a script
main.py
Your application must accept any inputs it needs as full-length arguments which are clear and self-explanatory.
For example, a start date and end date could be --start-date and --end-date respectively.
Running the Docker image without any inputs, like docker run <your-image-path>, must cause a help text to
be printed that explains which commands & arguments are available.
We recommend the use of click to simplify the setup of these commands.
A short example is below, but please refer to the click documentation for full details.
@click.command()
@click.option("--start_date", help="First date from which to run the analysis, RFC3339 formatted.")
@click.option("--end_date", help="Last date to which to run the analysis, RFC3339 formatted.")
def application(start_date, end_date):
pass # Insert your application code here
To build the docker image, store the content of the docker file above in a file named Dockerfile
in the same directory as your application code. Then run
$ docker build ./ -t {{application-name}}:latest {{application-name}}:{{version-string}}
{{version-string}} should be the version of your application following
semantic versioning. Suppose here the version is 1.2.3.
You can see the image that you have created by running
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
{{application-name}} latest aeb98c02f76f 11 seconds ago 398MB
{{application-name}} 1.2.3 aeb98c02f76f 11 seconds ago 398MB
Finally, export the Docker image as a compressed archive
docker save --output /path/to/your-application-name-{{version-string}}.tar.gz your-application-name:latest your-application-name:{{version-string}}
Share this tar file with us, and we will be able to deploy the latest version of your application.