11/23/2021»»Tuesday

Ubuntu Core Docker

April 14, 2020
  1. Ubuntu Core Docker Windows 10
  2. Ubuntu Core Docker Compose
  3. Ubuntu Core Docker Host

Hello everyone, in the last six months I have seen lots of talks regarding administrating the Azure from Ubuntu and many were asking about the steps to create a docker image with PowerShell Core installed and Az module pre-installed in it. So I have created this post for them to go through the below steps. After following these steps you can create a docker image which you can use later and can bundle the required PowerShell day to day operations scripts in it.

To understand this post you should have the basic knowledge of the docker container.

Tutorial

Luckily, Ubuntu Core has Docker snap package in the official snap package repository. So, you won’t have any trouble installing Docker on Raspberry Pi 3. To install Docker on Raspberry Pi 3, run the following command: $ sudo snap install docker. As you can see, Docker is being installed. It will take a while to complete. My VM is behind a proxy but using httpproxy env settings and sudo -E I seem to be able to get snappy to install docker: (amd64)[email protected]:$ snappy list -v Name Date Version Developer ubuntu-core 2016-02-25 16 ubuntu. docker 2016-04-18 1.6.2.005 canonical. generic-amd64 2016-02-25 1.4 canonical. (amd64)[email protected]:$.

Picture Credit: Pexels.com

And here we start.

Prerequisite: Assuming you already have an Azure VM built with Ubuntu image in your subscription and already have installed the docker in it.

In Ubuntu do the following.

cat > Dockerfile

docker build . -t powershell6-az-jan2020

Ubuntu Core Docker Windows 10

Ubuntu

# Download the Microsoft repository GPG keys

wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
Core

# Register the Microsoft repository GPG keys

# Update the list of products

sudo apt-get update

# Enable the “universe” repositories

# Install PowerShell

sudo apt-get install -y powershell

# Start PowerShell

Pwsh

Here are the steps.

docker run ubuntu

docker run -it ubuntu bash

apt-get install wget

wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb

dpkg -i packages-microsoft-prod.deb

apt-get update

apt-get install software-properties-common

apt-get update

apt-get install -y powershell

A standard image is below.

FROM ubuntu

run bash

run apt-get update

run apt-get install wget -y

run wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb

run dpkg -i packages-microsoft-prod.deb

run apt-get update

run apt-get install software-properties-common -y

run apt-get update

run apt-get install -y powershell -y

run pwsh -c “&{Install-Module -Name Az -AllowClobber -Scope AllUsers -Force}”

You may install .NET Core (If required)

dpkg –purge packages-microsoft-prod && sudo dpkg -i packages-microsoft-prod.deb

apt-get update

apt-get install {the .NET Core package}

For PowerShell 7.0 you can use this.

wget -q https://github.com/PowerShell/PowerShell/releases/download/v6.2.3/powershell_6.2.3-1.ubuntu.18.04_amd64.deb

dpkg -i powershell_7.0.0-1.ubuntu.18.04_amd64.deb

You can run docker build command next.

You can run a HelloWorld script as shown below once it’s build.

Docker
docker run powershell6-az-jan2020 pwsh -c “&{/devps/Helloworld.ps1}”

Ubuntu Core Docker Compose

A Final Image

FROM ubuntu

run bash

run apt-get update

run apt-get install wget -y

run wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb

run dpkg -i packages-microsoft-prod.deb

run apt-get update

run apt-get install software-properties-common -y

run apt-get update

run apt-get install -y powershell -y

run pwsh -c “&{Install-Module -Name Az -AllowClobber -Scope AllUsers -Force}”

run mkdir devps

copy /Documents/Powershell/SQlBackupreport.ps1 /devps/SQlBackupreport.ps1

In the last two lines above you can copy the existing ps1 script to the docker container. That’s all for today. You have a good day ahead.

Ubuntu Core Docker Host

Now alternately you can also pull the latest PowerShell ready image from Docker and run your scripts. I have published another post for this here.

Most Viewed Posts