Package: kedro-docker
Kedro-DockerDocker is a tool that makes it easier to create, deploy and run applications. It uses containers to package an application along with its dependencies and then runs the application in an isolated virtualised environment.Configuring a Docker container environment may become complex and tedious. Kedro-Docker significantly simplifies this process and reduces it to 2 steps:Build a Docker imageRun yourKedroproject in a Docker environmentNote:Kedro-Docker also makes it easy for you to run IPython and Jupyter Notebooks in a Docker container.How do I install Kedro-Docker?Kedro-Docker is a Python plugin. To install it:pipinstallkedro-dockerHow do I use Kedro-Docker?PrerequisitesThe following conditions must be true for Kedro-Docker to package your project:Make sure you haveinstalledDockerKedro-Docker assumes thatDocker daemonis up and running in your systemGenerating a DockerfileIn order to generate aDockerfilefor your project, navigate to the project's root directory and then run the following from the command line:kedrodockerinitThis command will generateDockerfile,.dockerignoreand.dive-cifiles for your project.Options:--with-spark- optional flag to create aDockerimagefile with Spark and Hadoop support-h, --help- show command help and exit.Build a Docker imageIn order to build a Docker image for your project, navigate to the project's root directory and then run the following from the command line:kedrodockerbuildBehind the scenes Kedro does the following:Creates a templateDockerfileand.dockerignorein the project root directory if those files don't already existBuilds the project image using theDockerfilefrom the project root directoryNote:When callingkedro docker buildyou can also pass any specific options fordocker buildby specifying--docker-argsoption. For example,kedro docker build --docker-args="--no-cache"instructs Docker not to use cache when building the image. You can learn more about available optionshere.Note:By default,kedro docker buildcreates an image without Spark and Hadoop.Note:By default, when callingkedro docker buildimage is built withpython:VERSION-busterimage, where VERSION is Python (major + minor) version from the current environment. By specifying--base-imageoption, different base image can be used. For examplekedro docker build --base-image="python:3.8-buster".Note:You can generate theDockerfile,.dockerignoreor.dive-cifiles without building the image by runningkedro docker init. This might be of use in case you would like to modify these files before the first build.The project Docker image will automatically be tagged as<project-root-dir>:latest, where<project-root-dir>is the name of the project root directory. To change the tag, you can add the--imagecommand line option, for example:kedro docker build --image my-project-tag.When building the image Kedro copies the contents of the current project into the image, however it ignores the locations specified in.dockerignorefile in order to prevent the propagation of potentially sensitive data into the image. We recommend mounting those volumes at runtime.Options:--uid- optional integer User ID for kedro user inside the container. Defaults to the current user's UID--gid- optional integer Group ID for kedro user inside the container. Defaults to the current user's GID--image- optional Docker image tag. Defaults to the project directory name--docker-args- optional string containing extra options fordocker buildcommand--with-spark- optional flag to create an image additionally with Spark and Hadoop--base-image- optional base Docker image. Default is Debian buster with the current environment Python version, e.g.python:3.8-buster-h, --help- show command help and exit.Run your project in a Docker environmentOnce the project image has been built, you can run the project using a Docker environment:kedrodockerrunThe command above will:Locate the image built in the previous sectionCopy the whole project directory into the/home/kedrocontainer pathExecutekedro runcommand in a new containerNote:Thekedro docker runcommand adds--rmflag to the underlyingdocker runcall, therefore the container will be automatically removed when it exits. Please make sure that you persist all necessary data outside the container at runtime to avoid data loss.By defaultkedro docker runwill use an image tagged as<project-root-dir>:latestto create a container. If you renamed your image in the previous step, please also provide an--imageoption with the corresponding image tag, for example:kedro docker run --image "my-custom-image:latest".When callingkedro docker runyou can also pass any specific options fordocker runby providing--docker-argsoption. Since--docker-argsmay contain multiple arguments, it's a good idea to add quotation marks. For example,kedro docker run --docker-args="--env KEY=MYVALUE"instructs Docker to set environment variableKEYtoMYVALUEin the container. You can learn more about available optionshere.All other CLI options will be appended tokedro runcommand inside the container. For example,kedro docker run --parallelwill runkedro run --parallelinside the container.Options:--image- Docker image name to be used, defaults to project root directory name--docker-args- optional string containing extra options fordocker runcommand-h, --help- show command help and exitAny other options will be treated askedro runcommand options.Interactive development with DockerIn addition tokedro docker runKedro also supports the following commands:kedro docker ipython- Run IPython session inside the containerkedro docker jupyter notebook- Start a Jupyter Notebook inside the containerkedro docker jupyter lab- Start a Jupyter Lab inside the containerOptions:--image- Docker image name to be used, defaults to project root directory name--docker-args- optional string containing extra options fordocker runcommand--port- host port that a container's port will be mapped to, defaults to 8888. This option applies tokedro docker jupytercommands only-h, --help- show command help and exitAny other options will be treated as correspondingkedrocommand CLI options. For example,kedro docker jupyter lab --NotebookApp.token='' --NotebookApp.password=''will run Jupyter Lab server without the password and token.Important:Please note that source code directory of a project (srcfolder) isnotmounted to the Docker container by default. This means that if you change any code insrcdirectory inside the container, those changes willnotbe saved to the host machine and will be completely lost when the container is terminated. In order to mount the whole project when running a Jupyter Lab, for example, run the following command:kedrodockerjupyterlab--docker-args"-v${PWD}:/home/kedro"Image analysis with DiveKedro-Docker allows to analyze the size efficiency of your project image by leveragingDive:kedrodockerdiveNote:By default Kedro-Docker calls Dive in CI mode. If you want to explore your image in the UI, runkedro docker dive --no-ci.Options:--ci / --no-ci- flag for running Dive in non-interactive mode. Defaults to true--ci-config-path- path to Dive CI config file. Defaults to.dive-ciin the project root directory--image- Docker image name to be used, defaults to project root directory name--docker-args- optional string containing extra options fordocker runcommand-h, --help- show command help and exit.Running custom commands with DockerYou can also run an arbitrary command inside Docker container by executingkedro docker cmd <CMD>, where<CMD>corresponds to the command that you want to execute. If<CMD>is not specified, this will executekedro runinside the container.Note:If you are runningkedrocommand, unlike in the previous sections, you should specify the whole command includingkedrokeyword. This is to allow the execution of non Kedro commands as well.For example:kedro docker cmd kedro testwill runkedro testinside the containerkedro docker cmdwill runkedro runinside the containerkedro docker cmd --docker-args="-it" /bin/bashwill create an interactivebashshell in the container (and allocate a pseudo-TTY connected to the container’s stdin).Options:--image- Docker image name to be used, defaults to project root directory name--docker-args- optional string containing extra options fordocker runcommand-h, --help- show command help and exit.Running Kedro-Docker withKedro-VizThese instructions allow you to accessKedro-Viz, Kedro's data pipeline visualisation tool, via Docker. In your terminal, run the following commands:pip download -d data --no-deps kedro-viz
kedro docker build
kedro docker cmd bash --docker-args="-it -u=0 -p=4141:4141"
pip install data/*.whl
kedro viz --host=0.0.0.0 --no-browserAnd then open127.0.0.1:4141in your preferred browser. Incidentally, ifkedro-vizis already installed in the Docker container (via requirements) then you can run:kedro docker cmd --docker-args="-p=4141:4141" kedro viz --host=0.0.0.0Can I contribute?Yes! Want to help build Kedro-Docker? Check out our guide tocontributing.What licence do you use?Kedro-Docker is licensed under theApache 2.0License.Python version support policyTheKedro-Dockersupports all Python versions that are actively maintained by the CPython core team. When aPython version reaches end of life, support for that version is dropped fromkedro-docker. This is not considered a breaking change.