{"id":5731,"date":"2020-12-24T03:12:37","date_gmt":"2020-12-24T11:12:37","guid":{"rendered":"https:\/\/officedevblogs.wpengine.com\/?p=5731"},"modified":"2020-12-24T03:12:37","modified_gmt":"2020-12-24T11:12:37","slug":"run-cli-microsoft-365-in-docker","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/run-cli-microsoft-365-in-docker\/","title":{"rendered":"Run CLI for Microsoft 365 in Docker"},"content":{"rendered":"<p>We are delighted to announce that <a href=\"https:\/\/aka.ms\/cli-m365\">CLI for Microsoft 365<\/a> Docker images are now available to download and use from the Docker Hub.<\/p>\n<p>If this doesn\u2019t mean a lot to you right now, then let me explain why we feel this is a big deal.<\/p>\n<p>Docker enables us to bundle a pre-configured version of CLI for Microsoft 365 together with all its required dependencies into a publicly downloadable image, which you can then use to create an isolated environment on your local machine, called a <code class=\"language-plaintext highlighter-rouge\">container<\/code>, where you can use the CLI for Microsoft 365 without cluttering your machine with dependencies, and all performed by executing just a single command.<\/p>\n<p>Sounds great, right? So how do you get started?<\/p>\n<p>Firstly, you will need to have Docker installed and running on your host machine, to do that, checkout the guides over in the Docker <a href=\"https:\/\/docs.docker.com\/get-docker\/\">documentation<\/a>, its free and can be installed on any operating system. Once you have Docker running on your machine, open up your command prompt of choice and run the below command.<\/p>\n<div class=\"language-plaintext highlighter-rouge\">\n<div class=\"highlight\">\n<pre class=\"highlight\"><code>docker run --rm -it m365pnp\/cli-microsoft365:latest\n<\/code><\/pre>\n<\/div>\n<\/div>\n<p>This command will instruct the Docker engine running on your host machine to start a container using an image called <code class=\"language-plaintext highlighter-rouge\">m365pnp\/cli-microsoft365<\/code>, as the <code class=\"language-plaintext highlighter-rouge\">:latest<\/code> tag is specified we are also telling the engine to get the image which contains the latest stable version of the CLI.<\/p>\n<p>As the image won\u2019t exist on your host machine yet, Docker will automatically download the image from the <a href=\"https:\/\/hub.docker.com\/r\/m365pnp\/cli-microsoft365\">Docker Hub<\/a>, where our images are publicly available, then start a new container which invoking an interactive terminal session inside the container, this is determined by the presence of the <code class=\"language-plaintext highlighter-rouge\">-it<\/code> switch in the <code class=\"language-plaintext highlighter-rouge\">docker run<\/code> command.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/garrytrinder.github.io\/public\/img\/cli-microsoft365\/run-cli-docker-download.png\" alt=\"Terminal displaying a bash interactive terminal session inside a docker container using m365pnp\/cli-microsoft365:latest image after being downloaded for the first time\" \/><\/p>\n<p>By default, the interactive terminal that is opened is a <code class=\"language-plaintext highlighter-rouge\">bash<\/code> shell, however if you prefer using <code class=\"language-plaintext highlighter-rouge\">PowerShell<\/code> then thats fine, we have you covered as we also bundle <code class=\"language-plaintext highlighter-rouge\">PowerShell 7<\/code> as part of the image.<\/p>\n<p>If you want to use PowerShell, simply add <code class=\"language-plaintext highlighter-rouge\">pwsh<\/code> to the end of the <code class=\"language-plaintext highlighter-rouge\">docker run<\/code> command and you will get a PowerShell session instead.<\/p>\n<div class=\"language-plaintext highlighter-rouge\">\n<div class=\"highlight\">\n<pre class=\"highlight\"><code>docker run --rm -it m365pnp\/cli-microsoft365:latest pwsh\n<\/code><\/pre>\n<\/div>\n<\/div>\n<p><img decoding=\"async\" src=\"https:\/\/garrytrinder.github.io\/public\/img\/cli-microsoft365\/run-cli-docker-pwsh.png\" alt=\"Terminal displaying a PowerShell interactive terminal session inside a docker container using m365pnp\/cli-microsoft365:latest image\" \/><\/p>\n<p>Now that you are at the interactive terminal, you can now invoke any CLI for Microsoft 365 command using the <code class=\"language-plaintext highlighter-rouge\">m365<\/code> prefix as it is already installed, to help you, we have even pre-configured tab command completion for you in both <code class=\"language-plaintext highlighter-rouge\">bash<\/code> and <code class=\"language-plaintext highlighter-rouge\">PowerShell<\/code>. Neat right.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/garrytrinder.github.io\/public\/img\/cli-microsoft365\/run-cli-docker-autocomplete.png\" alt=\"Terminal displaying a PowerShell interactive terminal session inside a docker container using m365pnp\/cli-microsoft365:latest image, the prompt is displaying command completion options for m365 command\" \/><\/p>\n<p>When you are done with your session, just type <code class=\"language-plaintext highlighter-rouge\">exit<\/code> and your interactive terminal will be closed and with that, the isolated container will also be stopped and removed, freeing up resources on your host machine, this is determined by the presence of the <code class=\"language-plaintext highlighter-rouge\">--rm<\/code> switch in the <code class=\"language-plaintext highlighter-rouge\">docker run<\/code> command.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/garrytrinder.github.io\/public\/img\/cli-microsoft365\/run-cli-docker-exit.png\" alt=\"Terminal displaying a PowerShell interactive terminal session inside a docker container using m365pnp\/cli-microsoft365:latest image, the prompt is at the host machine level after exit has been executed inside the container\" \/><\/p>\n<p>This doesn\u2019t mean that the image you just downloaded has been removed as well, this remains on your machine, we just removed the container instance that was started, so when you run the <code class=\"language-plaintext highlighter-rouge\">docker run<\/code> command again, this time you won\u2019t need to download the image and just head straight for the interactive terminal.<\/p>\n<p>As the container is removed after exiting the interactive terminal, everything stored in the container is removed, this includes any authentication information, therefore when you start a new container you will need to re-authenticate with Microsoft 365.<\/p>\n<p>Checkout our <a href=\"https:\/\/pnp.github.io\/cli-microsoft365\/user-guide\/run-cli-in-docker-container\/\">guide<\/a> for more details on how to use these images, including how to get the latest beta releases, update existing images, execute scripts stored on your local machine inside the running container and how to use your own Azure AD identity for connecting to Microsoft 365 from the running container.<\/p>\n<p>We will be releasing new beta and stable versions as part of our regular release cadence, so you will be able to use the new version of the CLI for Microsoft 365 in Docker immediately after our release to <code class=\"language-plaintext highlighter-rouge\">npm<\/code>.<\/p>\n<p>For a list of available tags, checkout the <a href=\"https:\/\/hub.docker.com\/r\/m365pnp\/cli-microsoft365\">m365pnp\/cli-microsoft365<\/a> repository on Docker Hub for the latest images.<\/p>\n<blockquote><p>CLI for Microsoft 365 is associated with the <a href=\"https:\/\/pnp.github.io\">Microsoft 365 Patterns and Practices<\/a> (PnP) organisation, which is a virtual team consisting of Microsoft employees and community members focused on helping the community make the best use of Microsoft products.<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/telemetry.sharepointpnp.com\/m365dev-blog\/run-cli-microsoft-365-in-docker\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We are delighted to announce that CLI for Microsoft 365 Docker images are now available to download and use from the Docker Hub.<\/p>\n","protected":false},"author":69079,"featured_media":25159,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11],"tags":[143,140],"class_list":["post-5731","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-office-add-ins","tag-cli-for-microsoft-365","tag-office-365-cli"],"acf":[],"blog_post_summary":"<p>We are delighted to announce that CLI for Microsoft 365 Docker images are now available to download and use from the Docker Hub.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/5731","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/users\/69079"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/comments?post=5731"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/5731\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media\/25159"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media?parent=5731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/categories?post=5731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/tags?post=5731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}