Skip to content

Docker Container Fails to Restart Due to Duplicate Key Violation #399

Closed

Description

@Cassie-2025

Describe the bug

After successfully starting the DocumentDB Docker container and connecting to the database, restarting the container causes it to fail. The container attempts to re-insert sample data on every restart, which results in a duplicate key violation error since the data already exists from the initial startup.

Reproduction Steps

Steps to reproduce the behavior:

Follow the README instructions at https://github.com/documentdb/documentdb/blob/main/README.md to pull and start the Docker container
Connect to the database successfully
Stop the Docker container (docker stop <container_name>)
Restart the Docker container (docker start <container_name>)
Observe that the container fails to start properly

Expected behavior

The Docker container should restart successfully without attempting to re-insert sample/initialization data that already exists in the database.

Actual behavior
The container fails to start on restart with the following error in the logs:

MongoBulkWriteError: Duplicate key violation on the requested collection: Index 'id'

Workaround
Dropping the entire database before restarting the container resolves the issue

Additional context

  • This appears to be a Docker image initialization script issue where the entrypoint/startup script unconditionally runs data insertion without checking if the data already exists.

  • Suggested fix: The initialization script should either:

    1. Check if data already exists before inserting, or
    2. Only run on first-time container initialization (not on restarts)

Activity

  1. added
    documentdb-local
    on Apr 3, 2026
  2. xgerman commented on Apr 3, 2026

    @xgerman
    Contributor

    Duplicate of #479

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

documentdb-local

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions