DockerTip #2 – How to Check if PowerShell is Running in a Docker Container?

As you may probably know, PowerShell can run in a Docker Container. Sometimes it can be useful to check if PowerShell is running inside a Docker Container instance before running a script for example. Then you can use this command:

PowerShell

1

2

3

4

5

PSC:\>Get-Service-Namecexecsvc

Status Name DisplayName

---------------------

Running cexecsvc Container Execution Agent

The option is to check if the service cexecsvc exist. If yes then it means that you are inside a Docker Container because this service only exists inside Docker containers.

I work as a System Engineer, based in Switzerland with a primary focus on Microsoft technologies. I have 8 years experience in administering Windows Servers.
.
I am a Microsoft MVP for Cloud & Datacenter Management. I also received the PowerShell Hero 2016 award by PowerShell.0rg. And finally, I am "MCSE: Cloud Platform and Infrastructure", "MCSA: Windows Servers", "Administering & Deploying SCCM", and CheckPoint CCSA certified.

Search

Rechercher :

Sponsors

Awards

Certifications

My IT training courses

About Nicolas

I work as a System Engineer, based in Switzerland with a primary focus on Microsoft technologies. I have 7 years experience in administering Windows Servers.
.
I am a Microsoft MVP for Cloud & Datacenter Management. I also received the PowerShell Hero 2016 award by PowerShell.0rg. And finally, I am “MCSE: Cloud Platform and Infrastructure”,”MCSA: Windows Servers” and “Administering & Deploying SCCM” certified.