You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Docker Container Fails to Restart Due to Duplicate Key Violation #399
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:
Check if data already exists before inserting, or
Only run on first-time container initialization (not on restarts)
Activity
xgerman commentedon Apr 3, 2026
Duplicate of #479