Is it possible to create a pre-seeded docker image based on mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator?

Jef Schraag-Halma 21 Reputation points
2023-03-24T15:31:06.18+00:00

To give our team a ready to query cosmos db container, pre-seeded with our data, I am trying to build a docker image based of mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator

My idea was to do something like this:

FROM mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest as cosmosdb

ENV AZURE_COSMOS_EMULATOR_PARTITION_COUNT=3
ENV AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=127.0.0.1

RUN . /usr/local/bin/cosmos/start.sh &

# wait for the service to spin up
RUN sleep 20

# put code here to seed the db here by connecting to 127.0.0.1:8081

However, when I check the resulting container, it did not start any emulator process and my seeding code fails with a message that nothing is available at port 8081.

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,640 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Oury Ba-MSFT 19,331 Reputation points Microsoft Employee
    2023-03-24T20:38:16.4133333+00:00

    @Jef Schraag-Halma Thank you for reaching out.

    It seems like you are trying to build a Docker image based on the Azure Cosmos DB Emulator for Linux. However, the Dockerfile you provided does not seem to start the emulator process correctly and failing with a message that nothing is available at port 8081.

    Please try the below. I assume that you are using SQ API

    docker run \
        --publish 8081:8081 \
        --publish 10250-10255:10250-10255 \
        --memory 3g --cpus=2.0 \
        --name=test-linux-emulator \
        --env AZURE_COSMOS_EMULATOR_PARTITION_COUNT=10 \
        --env AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=true \
        --env AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=$ipaddr \
        --interactive \
        --tty \
        mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
    

    OR try increasing the sleep time in your Dockerfile to give the emulator more time to start up. For example, you can try changing the sleep 20command to sleep 30 or sleep 60 to see if that helps.

    More troubleshooting tips:

    • Verify that the specific emulator container is in a running state.
    • Verify that no other applications are using emulator ports: 8081 and 10250-10255.
    • Verify that the container port 8081, is mapped correctly and accessible from an environment outside of the container.

    Run the emulator on Docker for Linux (Preview)

    Let me know if you are still having problems.

    Regards,

    Oury


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.