Step 1: Write a Dockerfile
The first step is to create a Dockerfile. This file will specify how to build our Docker image, including setting up the necessary environment variables and dependencies.
Create a file named Dockerfile
with the following content:
# Use the base image from the Azure Cognitive Services Text Analytics container
FROM mcr.microsoft.com/azure-cognitive-services/textanalytics/language
# Set environment variables
ENV Eula=accept
ENV Billing={ENDPOINT_URI}
ENV ApiKey={API_KEY}
# Expose port 5000
EXPOSE 5000
Replace {ENDPOINT_URI}
and {API_KEY}
with your actual endpoint URI and API key.
Why Set Environment Variables?
When running Azure AI services locally using Docker, we need to configure our container with specific settings that allow it to authenticate and connect to the Azure services. These settings include the acceptance of the End User License Agreement (EULA), the endpoint URI for billing purposes, and the API key for accessing the services.
- EULA Acceptance: Azure Cognitive Services require us to accept their End User License Agreement. This ensures that we agree to the terms and conditions set by Microsoft for using their services.
- Billing Endpoint: The billing endpoint URI is needed to track usage and ensure that our account is billed correctly for the services we consume.
- API Key: The API key is a critical piece of information that authenticates your requests to Azure Cognitive Services. Without this key, our requests to the service would be denied.
Step 2: Build the Docker Image
Once our Dockerfile is ready, we need to build the Docker image. This image will include all the necessary components to run Azure Cognitive Services locally.
Run the following command in the directory containing your Dockerfile:
docker build -t my-textanalytics-image .
This command builds the Docker image and tags it as my-textanalytics-image
.
Step 3: Run the Docker Container
With the Docker image built, we can now run a container from this image. The container will expose the necessary port and allocate resources as specified.
Use the following command to run your container:
docker run --rm -it -p 5000:5000 --memory 4g --cpus 1 my-textanalytics-image
This command runs the container with:
-
--rm
: Automatically removes the container when it exits.
-it
: Runs the container in interactive mode with a terminal.
-p 5000:5000
: Maps port 5000 on your local machine to port 5000 in the container.
--memory 8g
: Allocates 8GB of memory to the container.
--cpus 1
: Allocates 1 CPU to the container.


Step 4: Launch an Analysis
With your container running, you can now send requests to the Azure Cognitive Services endpoint hosted locally.
here are the endpoints :
In the navigator :

We can select Service Api Description to see the Api documentation at the left side.

We are now ready to use the service.

By following these steps, we can securely run Azure AI services locally using Docker. This setup not only enhances our application's security but also provides the flexibility to test and develop in a controlled environment.