Running via Docker
Relevant source files
The following files were used as context for generating this wiki page:
2ms (Too Many Secrets) is provided as a containerized application to simplify deployment and ensure a consistent execution environment across different infrastructures. By using Docker, users can execute secret scans without needing to install the Go runtime or manage local dependencies. The project publishes official images to checkmarx/2ms on Docker Hub.
Sources: README.md:46-48
Core Docker Execution
The primary way to run the tool is by pulling the image and executing it via the Docker CLI. The container entrypoint is configured to trigger the 2ms binary, allowing users to pass any supported scan commands (e.g., git, filesystem, confluence) and global flags directly to the container.
docker run checkmarx/2ms [command] [arguments] [flags]
Execution Flow within Container
The following diagram illustrates how a Docker command translates into a scan operation within the 2ms engine.
The Docker container acts as a wrapper for the Go-based engine, dispatching commands to specific plugins based on the provided arguments.
Sources: README.md:48-52, cmd/main.go:88-106
Mounting Local Filesystems
To scan local source code or directories from within a container, Docker volume mounting is required. The -v flag maps a host directory to a path inside the container, typically /repo.
| Plugin | Recommended Command Pattern | Internal Path Mapping |
|---|---|---|
| Git | docker run -v $(pwd):/repo checkmarx/2ms git /repo | /repo |
| Filesystem | docker run -v /local/path:/scan checkmarx/2ms filesystem --path /scan | /scan |
When scanning a Git repository, the project recommends mounting the repository to /repo inside the container to ensure the git command can access the .git metadata for history scanning.
Sources: README.md:54-61, plugins/git.go:102-115
Configuration and Hybrid Mode
Docker execution supports both command-line flags and configuration files. To use a YAML or JSON configuration file within Docker, the file must be mounted into the container's filesystem.
Volume Mapping for Configuration
In "Hybrid Configuration Mode," you can mount a specific configuration file and reference it using the --config flag.
docker run -v $(pwd)/.2ms.yml:/app/.2ms.yml checkmarx/2ms \
confluence --url https://example.atlassian.net/wiki \
--config /app/.2ms.yml
Configuration Priorities
The 2ms engine merges values from the mounted configuration file with any explicit command-line arguments provided in the docker run statement.
Sources: README.md:120-137, cmd/main.go:64-70
CI/CD Pipeline Integration
Docker images of 2ms are frequently used in automation pipelines to scan code during the build process.
GitHub Actions Integration
A common pattern involves using the docker run command within a GitHub Action runner. It is critical to use fetch-depth: 0 in the checkout step to allow the 2ms Docker container to see the full commit history when using the git command.
Sources: README.md:65-85, plugins/git.go:57-65
Available Plugins for Docker Execution
When running via Docker, all plugins registered in the core application are available. Each plugin handles different data sources by implementing the ISourceItem interface.
- Confluence: Scans pages and history revisions via the Atlassian API.
- Git: Scans local Git repositories, including history and branches.
- Filesystem: Scans local directories recursively, respecting
--ignore-patternflags. - Communication: Plugins for Slack, Discord, and Paligo are also included in the standard image.
Sources: cmd/main.go:72-80, plugins/confluence.go:51-66, plugins/filesystem.go:37-51
Conclusion
Running 2ms via Docker provides a portable, zero-install solution for secret detection. By leveraging volume mounts for local repositories and configuration files, users can integrate 2ms into local development workflows and CI/CD pipelines while maintaining the security and isolation of a containerized environment.