title: How to serve custom MLflow model with Docker?
body: <p>We have a project following essentially this
  <a href="https://github.com/mlflow/mlflow/tree/master/examples/docker" rel="nofollow noreferrer">docker example</a> with the only difference that we created a custom model similar to <a href="https://www.mlflow.org/docs/latest/models.html#custom-python-models" rel="nofollow noreferrer">this</a> whose code lies in a directory called <code>forecast</code>. We succeeded in running the model with <code>mlflow run</code>. The problem arises when we try to serve the model. After doing </p>
  
  <pre><code>mlflow models build-docker -m "runs:/my-run-id/my-model" -n "my-image-name"
  </code></pre>
  
  <p>we fail running the container with</p>
  
  <pre><code>docker run -p 5001:8080 "my-image-name"
  </code></pre>
  
  <p>with the following error:</p>
  
  <pre><code>ModuleNotFoundError: No module named 'forecast'
  </code></pre>
  
  <p>It seems that the docker image is not aware of the source code defining our custom model class.
  With Conda environnement the problem does not arise thanks to the <code>code_path</code> argument in <code>mlflow.pyfunc.log_model</code>.</p>
  
  <p>Our Dockerfile is very basic, with just <code>FROM continuumio/miniconda3:4.7.12, RUN pip install {model_dependencies}</code>.</p>
  
  <p>How to let the docker image know about the source code for deserialising the model and run it?</p>