This tutorial shows you how to run Atlas CLI commands with Docker in the following ways:
Run Docker in interactive mode
Run Docker as a daemon (detached mode)
To learn more about interactive mode and detached mode, see docker run.
For more information on our Atlas CLI docker image, see our Docker Hub repository.
You can also create a local Atlas deployment with Docker. To learn more, see Create a Local Atlas Deployment with Docker.
Complete The Prerequisites
Before you begin, complete the following prerequisites:
Install the Docker engine or Docker desktop.
Pull the Docker image to install the Atlas CLI with Docker.
(Optional) To run in interactive mode with an environment file, create an environment file that contains valid Atlas CLI environment variables, including API key environment variables that provide your API keys.
Follow These Steps
To run Atlas CLI commands with Docker, select one of the following options and follow the steps:
docker run --rm -it mongodb/atlas bash With an Environment File ~~~~~~~~~~~~~~~~~~~~~~~~ To get a shell using an environment file, run the following command, replacing ``atlas.env`` with the name of the environment file: .. code-block:: docker run --env-file atlas.env --rm -it mongodb/atlas bash .. step:: Authenticate and run Atlas CLI commands. .. note:: You must have access to the GitHub API in order to use the Atlas CLI in Docker. To authenticate and run commands, set up API keys in the `environment file <https://docs.docker.com/engine/reference/commandline/run/#env>`__. To learn more, see :ref:`Atlas CLI environment variables <atlas-cli-env-vars>`. To authenticate without an environment file, you can run :ref:`atlas auth login <atlas-auth-login>` to authenticate: .. code-block:: atlas auth login After you authenticate, you can run Atlas CLI commands. For example, you can run :ref:`atlas --help <atlas>` to learn about available commands: .. code-block:: atlas --help
docker run -d --name mongodb/atlas mongodb/atlas .. step:: Get a shell. Run the following command to get a shell with an environment file: .. code-block:: docker exec --env-file atlas.env --rm -it mongodb/atlas bash .. step:: Authenticate and run Atlas CLI commands. .. note:: You must have access to the GitHub API in order to use the Atlas CLI in Docker. To authenticate and run commands, set up API keys in the `environment file <https://docs.docker.com/engine/reference/commandline/run/#env>`__. To learn more, see :ref:`Atlas CLI environment variables <atlas-cli-env-vars>`. After you set up API keys, you can run Atlas CLI commands by adding ``docker exec --env-file ./atlas.env --rm mongodb/atlas`` before each Atlas CLI command. For example, to run the :ref:`atlas --help <atlas>` command with an environment file, run the following command, replacing ``atlas.env`` with the name of the environment file: .. code-block:: docker exec --env-file ./atlas.env --rm mongodb/atlas atlas --help