Powershell sobre Docker
Normalmente siempre se relaciona por historia Docker con Linux y Powershell con Windows, pero estos conceptos van cambiando día a día gracias a empresas como Microsoft, VMware, RedHat,… y la comunidad Open Source que siguen aportando potencial al mundo de los Containers.
Hoy quiero presentaros el Proyecto Powershell Core, que nos quiere acercar el potencial de Powershell a otros sistemas operativos como MacOS o Linux. La instalación de Powershell Core en MacOS ya os la enseñamos, pero hoy vamos a explicaros como hacerlo tanto en Windows como en Linux, para lo que utilizaré Centos 7, pero lo vamos a hacer mediante Containers.
Instalación Powershell Core sobre Windows 2019 Container
Voy a utilizar Windows Server 2019 para mostraros como se instala el Docker de Powershell Core.
Abrimos una consola…de “Powershell” como administrador, sí es raro, pero seguro que a alguien le parecerá útil jeje!!
Os explicamos como instalar Docker en Windows Server 2019, aunque creo que ya lo he hecho antes:
Instalamos los requisitos:
1 2 3 |
Install-WindowsFeature -Name Containers Uninstall-WindowsFeature Windows-Defender Restart-Computer -Force |
E instalamos Docker:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Install-Module -Name DockerMsftProvider -Repository PSGallery Untrusted repository You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): A Install-Package -Name docker -ProviderName DockerMsftProvider The package(s) come(s) from a package source that is not marked as trusted. Are you sure you want to install software from 'DockerDefault'? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): A |
Con todo instalado descargamos las imágenes en las que se basa Windows Server 2019 para levantar Containers en el sistema:
1 2 |
docker image pull mcr.microsoft.com/windows/servercore:1809 docker image pull mcr.microsoft.com/windows/nanoserver:1809 |
Éstas son opcionales:
1 2 |
docker image pull microsoft/dotnet:2.1-sdk-nanoserver-1809 docker image pull microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-1809 |
Y como no podía ser de otra forma la de powershell core:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
docker pull microsoft/powershell Using default tag: latest latest: Pulling from microsoft/powershell 65014b3c3121: Pull complete 2ac060f1ef06: Extracting [============================> ] 178.3MB/315.3MB 2718391252e9: Download complete bfa0038ff221: Download complete 49c890372586: Download complete ea12e6b44443: Download complete 5f75c9b59fb4: Download complete 7b7f17f0a6b7: Download complete 7505b5b5d62d: Download complete 3d36545e5af1: Download complete 51d103d36804: Download complete ba56d6b5d2fe: Download complete 5d176f6eeebb: Download complete 0bc8e07e22fd: Download complete |
Ahora nos queda lanzar un Container de Powershell Core:
1 |
docker run -it microsoft/powershell:latest powershell |
Comprobamos:
1 2 3 |
docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0efaeae6e175 microsoft/powershell:latest "powershell" About a minute ago Up About a minute nervous_pike |
Nos conectamos y hacemos alguna prueba:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
docker attach 0efaeae6e175 Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. PS C:\> hostname 0efaeae6e175 PS C:\> Get-Service Status Name DisplayName ------ ---- ----------- Stopped AppIDSvc Application Identity Stopped AppMgmt Application Management Stopped AppReadiness App Readiness Stopped AppXSvc AppX Deployment Service (AppXSVC) Stopped BFE Base Filtering Engine Stopped BITS Background Intelligent Transfer Ser... Stopped CertPropSvc Certificate Propagation Running cexecsvc Container Execution Agent Stopped ClipSVC Client License Service (ClipSVC) Stopped COMSysApp COM+ System Application Running CoreMessagingRe... CoreMessaging Running CryptSvc Cryptographic Services Running DcomLaunch DCOM Server Process Launcher Stopped defragsvc Optimize drives Stopped DeviceInstall Device Install Service Running Dhcp DHCP Client Stopped diagnosticshub.... Microsoft (R) Diagnostics Hub Stand... Running DiagTrack Connected User Experiences and Tele... Running Dnscache DNS Client Stopped DoSvc Delivery Optimization Stopped DPS Diagnostic Policy Service Stopped EapHost Extensible Authentication Protocol Stopped EFS Encrypting File System (EFS) Running EventLog Windows Event Log Running EventSystem COM+ Event System Running gpsvc Group Policy Client Stopped hidserv Human Interface Device Service Stopped HvHost HV Host Service Stopped IKEEXT IKE and AuthIP IPsec Keying Modules Running iphlpsvc IP Helper Stopped KeyIso CNG Key Isolation Stopped KPSSVC KDC Proxy Server service (KPS) Stopped KtmRm KtmRm for Distributed Transaction C... Stopped LanmanServer Server Running LanmanWorkstation Workstation Stopped lltdsvc Link-Layer Topology Discovery Mapper Stopped lmhosts TCP/IP NetBIOS Helper Running LSM Local Session Manager Stopped mpssvc Windows Defender Firewall Running MSDTC Distributed Transaction Coordinator Stopped MSiSCSI Microsoft iSCSI Initiator Service Stopped msiserver Windows Installer Stopped NcaSvc Network Connectivity Assistant Stopped Netlogon Netlogon Stopped netprofm Network List Service Stopped NetSetupSvc Network Setup Service Stopped NetTcpPortSharing Net.Tcp Port Sharing Service Stopped NlaSvc Network Location Awareness Running nsi Network Store Interface Service Stopped PerfHost Performance Counter DLL Host Stopped pla Performance Logs & Alerts Stopped PlugPlay Plug and Play Stopped PolicyAgent IPsec Policy Agent Stopped Power Power Running ProfSvc User Profile Service Stopped RasMan Remote Access Connection Manager Stopped RemoteAccess Routing and Remote Access Running RemoteRegistry Remote Registry Running RpcEptMapper RPC Endpoint Mapper Running RpcSs Remote Procedure Call (RPC) Stopped RSoPProv Resultant Set of Policy Provider Stopped sacsvr Special Administration Console Helper Running SamSs Security Accounts Manager Stopped SCardSvr Smart Card Stopped ScDeviceEnum Smart Card Device Enumeration Service Running Schedule Task Scheduler Stopped SCPolicySvc Smart Card Removal Policy Stopped seclogon Secondary Logon Running SENS System Event Notification Service Stopped Sense Windows Defender Advanced Threat Pr... Stopped SessionEnv Remote Desktop Configuration Stopped SgrmBroker System Guard Runtime Monitor Broker Stopped SharedAccess Internet Connection Sharing (ICS) Running smphost Microsoft Storage Spaces SMP Stopped SNMPTRAP SNMP Trap Stopped sppsvc Software Protection Stopped ssh-agent OpenSSH Authentication Agent Stopped SstpSvc Secure Socket Tunneling Protocol Se... Stopped StateRepository State Repository Service Stopped svsvc Spot Verifier Stopped swprv Microsoft Software Shadow Copy Prov... Running SysMain SysMain Running SystemEventsBroker System Events Broker Stopped TermService Remote Desktop Services Stopped TieringEngineSe... Storage Tiers Management Running TimeBrokerSvc Time Broker Stopped TrustedInstaller Windows Modules Installer Stopped UALSVC User Access Logging Service Stopped UmRdpService Remote Desktop Services UserMode Po... Running UserManager User Manager Running UsoSvc Update Orchestrator Service Stopped VaultSvc Credential Manager Stopped vds Virtual Disk Stopped vmicguestinterface Hyper-V Guest Service Interface Stopped vmicheartbeat Hyper-V Heartbeat Service Stopped vmickvpexchange Hyper-V Data Exchange Service Stopped vmicrdv Hyper-V Remote Desktop Virtualizati... Stopped vmicshutdown Hyper-V Guest Shutdown Service Stopped vmictimesync Hyper-V Time Synchronization Service Stopped vmicvmsession Hyper-V PowerShell Direct Service Stopped vmicvss Hyper-V Volume Shadow Copy Requestor Stopped VSS Volume Shadow Copy Stopped W32Time Windows Time Stopped WaaSMedicSvc Windows Update Medic Service Stopped WdiServiceHost Diagnostic Service Host Stopped WdiSystemHost Diagnostic System Host Stopped Wecsvc Windows Event Collector Stopped WerSvc Windows Error Reporting Service Running WinHttpAutoProx... WinHTTP Web Proxy Auto-Discovery Se... Running Winmgmt Windows Management Instrumentation Running WinRM Windows Remote Management (WS-Manag... Stopped wisvc Windows Insider Service Stopped wmiApSrv WMI Performance Adapter Stopped wuauserv Windows Update |
Instalación Powershell Core sobre Centos 7 Container
En Centos la cosa es más sencilla. Os explico como instalar docker en unos comandos:
Actualizamos sistema e instalamos requisitos:
1 |
yum update |
1 |
yum install yum-utils device-mapper-persistent-data lvm2 |
Instalamos el repo:
1 |
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo |
Instalamos docker-ce:
1 |
yum install docker-ce |
Habilitamos servicio:
1 2 3 |
systemctl start docker systemctl enable docker |
Con docker instalado:
1 2 3 4 5 6 7 8 9 |
[root@glusterfs01 ~]# docker pull microsoft/powershell Using default tag: latest latest: Pulling from microsoft/powershell 84ed7d2f608f: Pull complete be2bf1c4a48d: Pull complete a5bdc6303093: Pull complete e9055237d68d: Pull complete b70555365592: Pull complete 00c78a40f869: Extracting 45.68MB/83.59MB |
Esperamos a que termine y repetimos la jugada de Windows en Linux:
1 2 3 4 5 6 7 8 9 |
[root@glusterfs01 ~]# docker run -it microsoft/powershell PowerShell 6.1.2 Copyright (c) Microsoft Corporation. All rights reserved. https://aka.ms/pscore6-docs Type 'help' to get help. PS /> hostname a0d0f849db76 |
Te ha gustado la entrada SGUENOS EN TWITTER O INVITANOS A UN CAFE?