Run CLI for Microsoft 365 in Docker

Published Mar 13 2021 02:34 AM 2,493 Views

We are delighted to announce that CLI for Microsoft 365 Docker images are now available to download and use from the Docker Hub.

 

If this doesn’t mean a lot to you right now, then let me explain why we feel this is a big deal.

 

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 container, where you can use the CLI for Microsoft 365 without cluttering your machine with dependencies, and all performed by executing just a single command.

 

Sounds great, right? So how do you get started?

 

Firstly, you will need to have Docker installed and running on your host machine, to do that, checkout the guides over in the Docker documentation, 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.

 

docker run --rm -it m365pnp/cli-microsoft365:latest

 

This command will instruct the Docker engine running on your host machine to start a container using an image called m365pnp/cli-microsoft365, as the :latest tag is specified we are also telling the engine to get the image which contains the latest stable version of the CLI.

 

As the image won’t exist on your host machine yet, Docker will automatically download the image from the Docker Hub, 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 -it switch in the docker run command.

 

garrytrinder_0-1615630685864.png

 

By default, the interactive terminal that is opened is a bash shell, however if you prefer using PowerShell then thats fine, we have you covered as we also bundle PowerShell 7 as part of the image.

If you want to use PowerShell, simply add pwsh to the end of the docker run command and you will get a PowerShell session instead.

 

docker run --rm -it m365pnp/cli-microsoft365:latest pwsh

 

garrytrinder_1-1615630685843.png

 

Now that you are at the interactive terminal, you can now invoke any CLI for Microsoft 365 command using the m365prefix as it is already installed, to help you, we have even pre-configured tab command completion for you in both bash and PowerShell. Neat right.

 

garrytrinder_2-1615630685839.png

 

When you are done with your session, just type exit 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 --rm switch in the docker run command.

 

garrytrinder_3-1615630685863.png

 

This doesn’t 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 docker run command again, this time you won’t need to download the image and just head straight for the interactive terminal.

 

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.

 

Checkout our guide 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.

 

We also demonstrated how to run CLI for Microsoft 365 in Docker container in the General Microsoft 365 Development Special Interest Group (SIG) - Bi-weekly sync call recorded on February 18, 2021.

 

 

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 npm.

 

For a list of available tags, checkout the m365pnp/cli-microsoft365 repository on Docker Hub for the latest images.

%3CLINGO-SUB%20id%3D%22lingo-sub-2207125%22%20slang%3D%22en-US%22%3ERun%20CLI%20for%20Microsoft%20365%20in%20Docker%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2207125%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20are%20delighted%20to%20announce%20that%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fcli-m365%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ECLI%20for%20Microsoft%20365%3C%2FA%3E%20Docker%20images%20are%20now%20available%20to%20download%20and%20use%20from%20the%20Docker%20Hub.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20this%20doesn%E2%80%99t%20mean%20a%20lot%20to%20you%20right%20now%2C%20then%20let%20me%20explain%20why%20we%20feel%20this%20is%20a%20big%20deal.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDocker%20enables%20us%20to%20bundle%20a%20pre-configured%20version%20of%20CLI%20for%20Microsoft%20365%20together%20with%20all%20its%20required%20dependencies%20into%20a%20publicly%20downloadable%20image%2C%20which%20you%20can%20then%20use%20to%20create%20an%20isolated%20environment%20on%20your%20local%20machine%2C%20called%20a%3CCODE%20class%3D%22language-plaintext%20highlighter-rouge%22%3Econtainer%3C%2FCODE%3E%2C%20where%20you%20can%20use%20the%20CLI%20for%20Microsoft%20365%20without%20cluttering%20your%20machine%20with%20dependencies%2C%20and%20all%20performed%20by%20executing%20just%20a%20single%20command.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESounds%20great%2C%20right%3F%20So%20how%20do%20you%20get%20started%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFirstly%2C%20you%20will%20need%20to%20have%20Docker%20installed%20and%20running%20on%20your%20host%20machine%2C%20to%20do%20that%2C%20checkout%20the%20guides%20over%20in%20the%20Docker%20%3CA%20href%3D%22https%3A%2F%2Fdocs.docker.com%2Fget-docker%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Edocumentation%3C%2FA%3E%2C%20its%20free%20and%20can%20be%20installed%20on%20any%20operating%20system.%20Once%20you%20have%20Docker%20running%20on%20your%20machine%2C%20open%20up%20your%20command%20prompt%20of%20choice%20and%20run%20the%20below%20command.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CDIV%20class%3D%22language-plaintext%20highlighter-rouge%22%3E%0A%3CDIV%20class%3D%22highlight%22%3E%0A%3CPRE%20class%3D%22highlight%22%3E%3CCODE%3Edocker%20run%20--rm%20-it%20m365pnp%2Fcli-microsoft365%3Alatest%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20command%20will%20instruct%20the%20Docker%20engine%20running%20on%20your%20host%20machine%20to%20start%20a%20container%20using%20an%20image%20called%3CCODE%20class%3D%22language-plaintext%20highlighter-rouge%22%3Em365pnp%2Fcli-microsoft365%3C%2FCODE%3E%2C%20as%20the%3CCODE%20class%3D%22language-plaintext%20highlighter-rouge%22%3E%3Alatest%3C%2FCODE%3Etag%20is%20specified%20we%20are%20also%20telling%20the%20engine%20to%20get%20the%20image%20which%20contains%20the%20latest%20stable%20version%20of%20the%20CLI.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20the%20image%20won%E2%80%99t%20exist%20on%20your%20host%20machine%20yet%2C%20Docker%20will%20automatically%20download%20the%20image%20from%20the%20%3CA%20href%3D%22https%3A%2F%2Fhub.docker.com%2Fr%2Fm365pnp%2Fcli-microsoft365%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EDocker%20Hub%3C%2FA%3E%2C%20where%20our%20images%20are%20publicly%20available%2C%20then%20start%20a%20new%20container%20which%20invoking%20an%20interactive%20terminal%20session%20inside%20the%20container%2C%20this%20is%20determined%20by%20the%20presence%20of%20the%3CCODE%20class%3D%22language-plaintext%20highlighter-rouge%22%3E-it%3C%2FCODE%3Eswitch%20in%20the%3CCODE%20class%3D%22language-plaintext%20highlighter-rouge%22%3Edocker%20run%3C%2FCODE%3Ecommand.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22garrytrinder_0-1615630685864.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F263355i6DAB65DB77FE2782%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22garrytrinder_0-1615630685864.png%22%20alt%3D%22garrytrinder_0-1615630685864.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBy%20default%2C%20the%20interactive%20terminal%20that%20is%20opened%20is%20a%3CCODE%20class%3D%22language-plaintext%20highlighter-rouge%22%3Ebash%3C%2FCODE%3Eshell%2C%20however%20if%20you%20prefer%20using%3CCODE%20class%3D%22language-plaintext%20highlighter-rouge%22%3EPowerShell%3C%2FCODE%3Ethen%20thats%20fine%2C%20we%20have%20you%20covered%20as%20we%20also%20bundle%3CCODE%20class%3D%22language-plaintext%20highlighter-rouge%22%3EPowerShell%207%3C%2FCODE%3Eas%20part%20of%20the%20image.%3C%2FP%3E%0A%3CP%3EIf%20you%20want%20to%20use%20PowerShell%2C%20simply%20add%3CCODE%20class%3D%22language-plaintext%20highlighter-rouge%22%3Epwsh%3C%2FCODE%3Eto%20the%20end%20of%20the%3CCODE%20class%3D%22language-plaintext%20highlighter-rouge%22%3Edocker%20run%3C%2FCODE%3Ecommand%20and%20you%20will%20get%20a%20PowerShell%20session%20instead.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CDIV%20class%3D%22language-plaintext%20highlighter-rouge%22%3E%0A%3CDIV%20class%3D%22highlight%22%3E%0A%3CPRE%20class%3D%22highlight%22%3E%3CCODE%3Edocker%20run%20--rm%20-it%20m365pnp%2Fcli-microsoft365%3Alatest%20pwsh%3C%2FCODE%3E%3C%2FPRE%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22garrytrinder_1-1615630685843.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F263354iB47662BC6BBD11A4%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22garrytrinder_1-1615630685843.png%22%20alt%3D%22garrytrinder_1-1615630685843.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20that%20you%20are%20at%20the%20interactive%20terminal%2C%20you%20can%20now%20invoke%20any%20CLI%20for%20Microsoft%20365%20command%20using%20the%3CCODE%20class%3D%22language-plaintext%20highlighter-rouge%22%3Em365%3C%2FCODE%3Eprefix%20as%20it%20is%20already%20installed%2C%20to%20help%20you%2C%20we%20have%20even%20pre-configured%20tab%20command%20completion%20for%20you%20in%20both%3CCODE%20class%3D%22language-plaintext%20highlighter-rouge%22%3Ebash%3C%2FCODE%3Eand%3CCODE%20class%3D%22language-plaintext%20highlighter-rouge%22%3EPowerShell%3C%2FCODE%3E.%20Neat%20right.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22garrytrinder_2-1615630685839.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F263356i69B5B2CE4731276E%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22garrytrinder_2-1615630685839.png%22%20alt%3D%22garrytrinder_2-1615630685839.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhen%20you%20are%20done%20with%20your%20session%2C%20just%20type%3CCODE%20class%3D%22language-plaintext%20highlighter-rouge%22%3Eexit%3C%2FCODE%3Eand%20your%20interactive%20terminal%20will%20be%20closed%20and%20with%20that%2C%20the%20isolated%20container%20will%20also%20be%20stopped%20and%20removed%2C%20freeing%20up%20resources%20on%20your%20host%20machine%2C%20this%20is%20determined%20by%20the%20presence%20of%20the%3CCODE%20class%3D%22language-plaintext%20highlighter-rouge%22%3E--rm%3C%2FCODE%3Eswitch%20in%20the%3CCODE%20class%3D%22language-plaintext%20highlighter-rouge%22%3Edocker%20run%3C%2FCODE%3Ecommand.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22garrytrinder_3-1615630685863.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F263357iDAE5D5CDE7AD769F%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22garrytrinder_3-1615630685863.png%22%20alt%3D%22garrytrinder_3-1615630685863.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20doesn%E2%80%99t%20mean%20that%20the%20image%20you%20just%20downloaded%20has%20been%20removed%20as%20well%2C%20this%20remains%20on%20your%20machine%2C%20we%20just%20removed%20the%20container%20instance%20that%20was%20started%2C%20so%20when%20you%20run%20the%3CCODE%20class%3D%22language-plaintext%20highlighter-rouge%22%3Edocker%20run%3C%2FCODE%3Ecommand%20again%2C%20this%20time%20you%20won%E2%80%99t%20need%20to%20download%20the%20image%20and%20just%20head%20straight%20for%20the%20interactive%20terminal.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20the%20container%20is%20removed%20after%20exiting%20the%20interactive%20terminal%2C%20everything%20stored%20in%20the%20container%20is%20removed%2C%20this%20includes%20any%20authentication%20information%2C%20therefore%20when%20you%20start%20a%20new%20container%20you%20will%20need%20to%20re-authenticate%20with%20Microsoft%20365.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECheckout%20our%20%3CA%20href%3D%22https%3A%2F%2Fpnp.github.io%2Fcli-microsoft365%2Fuser-guide%2Frun-cli-in-docker-container%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Eguide%3C%2FA%3E%20for%20more%20details%20on%20how%20to%20use%20these%20images%2C%20including%20how%20to%20get%20the%20latest%20beta%20releases%2C%20update%20existing%20images%2C%20execute%20scripts%20stored%20on%20your%20local%20machine%20inside%20the%20running%20container%20and%20how%20to%20use%20your%20own%20Azure%20AD%20identity%20for%20connecting%20to%20Microsoft%20365%20from%20the%20running%20container.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20also%20demonstrated%20how%20to%20run%20CLI%20for%20Microsoft%20365%20in%20Docker%20container%20in%20the%20%3CSPAN%3EGeneral%20Microsoft%20365%20Development%20Special%20Interest%20Group%20(SIG)%20-%20Bi-weekly%20sync%20call%20recorded%20on%20February%2018%2C%202021.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3C%2FP%3E%3CDIV%20class%3D%22video-embed-center%20video-embed%22%3E%3CIFRAME%20class%3D%22embedly-embed%22%20src%3D%22https%3A%2F%2Fcdn.embedly.com%2Fwidgets%2Fmedia.html%3Fsrc%3Dhttps%253A%252F%252Fwww.youtube.com%252Fembed%252FXpJjAsMEPdE%253Fstart%253D1%26amp%3Bdisplay_name%3DYouTube%26amp%3Burl%3Dhttps%253A%252F%252Fwww.youtube.com%252Fwatch%253Fv%253DXpJjAsMEPdE%26amp%3Bimage%3Dhttp%253A%252F%252Fi.ytimg.com%252Fvi%252FXpJjAsMEPdE%252Fhqdefault.jpg%26amp%3Bkey%3Dfad07bfa4bd747d3bdea27e17b533c0e%26amp%3Btype%3Dtext%252Fhtml%26amp%3Bschema%3Dyoutube%22%20width%3D%22400%22%20height%3D%22225%22%20scrolling%3D%22no%22%20title%3D%22YouTube%20embed%22%20frameborder%3D%220%22%20allow%3D%22autoplay%3B%20fullscreen%22%20allowfullscreen%3D%22true%22%3E%3C%2FIFRAME%3E%3C%2FDIV%3E%3CP%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20will%20be%20releasing%20new%20beta%20and%20stable%20versions%20as%20part%20of%20our%20regular%20release%20cadence%2C%20so%20you%20will%20be%20able%20to%20use%20the%20new%20version%20of%20the%20CLI%20for%20Microsoft%20365%20in%20Docker%20immediately%20after%20our%20release%20to%3CCODE%20class%3D%22language-plaintext%20highlighter-rouge%22%3Enpm%3C%2FCODE%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20a%20list%20of%20available%20tags%2C%20checkout%20the%20%3CA%20href%3D%22https%3A%2F%2Fhub.docker.com%2Fr%2Fm365pnp%2Fcli-microsoft365%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Em365pnp%2Fcli-microsoft365%3C%2FA%3E%20repository%20on%20Docker%20Hub%20for%20the%20latest%20images.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2207125%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EWe%20are%20delighted%20to%20announce%20that%20%3C%2FSPAN%3E%3CA%20title%3D%22CLI%20for%20Microsoft%20365%22%20href%3D%22https%3A%2F%2Faka.ms%2Fcli-m365%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ECLI%20for%20Microsoft%20365%3C%2FA%3E%26nbsp%3B%3CSPAN%3EDocker%20images%20are%20now%20available%20to%20download%20and%20use%20from%20the%20Docker%20Hub.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2207125%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ECLI%20for%20Microsoft%20365%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ECommunity%20call%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDocker%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EGetting%20started%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EHow%20to%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎Mar 13 2021 02:34 AM
Updated by: