0

Got all machine learning model that i have registered into a docker image using model package. How do I deploy this docker image to a web service

# Define the deployment configuration
aciconfig = AciWebservice.deploy_configuration(
      cpu_cores = 1,
      memory_gb = 1,
      dns_name_label = os.environ['ACI_DNS_NAME_LABEL'])


#create env 
environment = Environment('env')
environment.python.conda_dependencies = CondaDependencies.create(conda_packages=[
'pip==20.2.4'],
 pip_packages=[
 'azureml-defaults',
 'joblib',
 'numpy',
 'scikit-learn'])

    
inf_conf = InferenceConfig(entry_script="score.py",environment=environment)
#crete docker image    
docker_image = Model.package(ws,models_latest, inf_conf,image_name="imgname")
docker_image.wait_for_creation(show_output=True) 
docker_image.pull()
tommyt
  • 309
  • 5
  • 15

1 Answers1

0

Before starting the deployment, we need to have a trained model handy for the deployment. As the trained model is available and the process needs to be deployed as a web service.

Check out the procedure of creating a container resource for the web app.

enter image description here

Click on “create a resource

enter image description here

Click on “Container” in the left panel

enter image description here

Click on Web App for Containers and click on create

enter image description here

Give the details required and keep the container details handy for further usage.

docker_image = Model.package(ws,models_latest, inf_conf,image_name="imgname")
docker_image.wait_for_creation(show_output=True) 
docker_image.pull()

After the **image.pull()** method was used, we will get the process notification regarding the docker image which we created.

Status: Downloaded newer image for myworkspacef78fd10.azurecr.io/package:packagenumber

After downloading the docker image, user the command “docker images” to get the list of local images

REPOSITORY          name.azurecr.io/package
TAG                 Your docker tag
IMAGE ID            Your Image ID
CREATED             Time created
SIZE                Size of the container

The data contains the <image id> which we need to replace in the below syntax

docker run -p 6789:5001 --name containername <imageid>

**6789** is the local port number and 5001 is the web service listening number.

Create a Dockerfile and dependencies

package = Model.package(ws, [model], inference_config, generate_dockerfile=True)
package.wait_for_creation(show_output=True)
# Download the package.
package.save("./imagefiles")
# Get the Azure container registry that the model/Dockerfile uses.
acr=package.get_container_registry()
print("Address:", acr.address)
print("Username:", acr.username)
print("Password:", acr.password)

the above code block helps us to download the files required to build the image in **imagefiles** directory.

We need to use the shell to authenticate the docker image

docker login <address> -u <username> -p <password>

Now, build the docker image

docker build --tag myimage <imagefiles>

To run the container use the command below, which is listening based on the port and web service number.

docker run -p 6789:5001 --name mycontainer image_name:latest
Sairam Tadepalli
  • 1,563
  • 1
  • 3
  • 11