Dotnet-docker: dotnet-core and Powershell-core in one image

Created on 10 Oct 2017  路  10Comments  路  Source: dotnet/dotnet-docker

preface: i'm new on docker/linux....

my requirement: a docker (linux) image where dotnet (sdk) and Powershell-Core is available together.
it is really difficult to do that currently because of different base images (jessie/stretch/xenial)
different installation prerequisites etc....

With the latest Powershell beta relase (a few days old) a debian package (jessie) was available the first time and i was able to compile a image, but i'm not sure if my dockerfile-implementation was the best way (lot of hacks and i'm new on docker/linux)
Anyone can provide a docker file for that scenario - assuming there is a lot of reasons to combine this two products...

or another idea:

please prepare the dotnet-sdk package in a way that i must only "apt-get install powershell" inside my own image.
assuming that most/all of the installation prerequisites are identical for dotnet-core and PS-Core....

regards
Werner

question

Most helpful comment

You could easily put @Boggin's steps into a Dockerfile to make it easier to build.

FROM microsoft/dotnet:2.0.0-sdk

RUN curl -SL https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-beta.8/powershell_6.0.0-beta.8-1.debian.9_amd64.deb --output powershell.deb\
    && dpkg -i powershell.deb \
    && rm powershell.deb

This makes use of the .NET image so that you don't have to rebuild it and can share the Docker layers.

All 10 comments

I'm looking to do something similar. In my testing so far I've used the Dockerfile for the 2.0.0-sdk-stretch image.
PS> iwr https://raw.githubusercontent.com/dotnet/dotnet-docker/master/2.0/sdk/stretch/amd64/Dockerfile -o Dockerfile
PS> docker build .

To check I can run PowerShell on this I've opened a command prompt and done a simple install.
PS> docker run -it <container_id>
root# wget https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-beta.8/powershell_6.0.0-beta.8-1.debian.9_amd64.deb
root# dpkg -i powershell_6.0.0-beta.8-1.debian.9_amd64.deb

Quick test to see if that works:
root# powershell
PS> get-date
PS> exit

Commit your changes to a new image:
PS> docker commit <container_id> your-name-here/dotnet-powershell

I can now use my new image and it has PowerShell along with dotnet core 2.0.0 SDK.

The other option is to modify the Dockerfile with the instructions for installing PowerShell.

You could easily put @Boggin's steps into a Dockerfile to make it easier to build.

FROM microsoft/dotnet:2.0.0-sdk

RUN curl -SL https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-beta.8/powershell_6.0.0-beta.8-1.debian.9_amd64.deb --output powershell.deb\
    && dpkg -i powershell.deb \
    && rm powershell.deb

This makes use of the .NET image so that you don't have to rebuild it and can share the Docker layers.

I tested @MichaelSimons suggestion with the addition of making PowerShell the default shell (an idea from the microsoft/powershell Dockerfile) and it worked just fine.

# Install PowerShell Core 6.0
ENV POWERSHELL_DOWNLOAD_URL https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-beta.8/powershell_6.0.0-beta.8-1.debian.9_amd64.deb

RUN curl -SL $POWERSHELL_DOWNLOAD_URL --output powershell.deb \
    && dpkg -i powershell.deb \
    && rm powershell.deb

# Use PowerShell as the default shell
# Use array to avoid Docker prepending /bin/sh -c
CMD [ "powershell" ]

Thanks a lot for all that suggestions!

My "stretch" sample is up and running by using suggestions from the first two answers/posts from Boggin and MichaelSimons!!

Now i'm working on a sample with jessie using this instructions for installing powershell.

here my dockerfile:

FROM microsoft/dotnet:2.0.0-sdk-jessie

RUN apt-get update && apt-get -y install apt-utils
RUN apt-get update && apt-get -y install curl apt-transport-https

RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-jessie-prod jessie main" > /etc/apt/sources.list.d/microsoft.list'
RUN apt-get update && apt-get -y install powershell

Powershell is working after that but i see some red lines during compiling => any idea ?
not sure if that "RUN sh -c...." is the best way to do that in a dockerfile.

i like this way for the moment because it avoids the download path literals used in the other samples....

regards
Werner

@WernerMairl i think you can just trim it to

RUN echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-jessie-prod jessie main" > /etc/apt/sources.list.d/microsoft.list

@tuananh thank you, that works!

i have stil the following red lines during docker build - but the build completes with success and PS is working - any idea from the linux experts?

debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (This frontend requires a controlling tty.)
debconf: falling back to frontend: Teletype
dpkg-preconfigure: unable to re-open stdin:

@WernerMairl can you try to RUN export TERM=xterm or maybe set environment variable after FROM

FROM microsoft/dotnet:2.0.0-sdk-jessie
ENV TERM=xterm

@WernerMairl, I think you may need to set DEBIAN_FRONTEND to noninteractive. Also I you may want to consider cleaning up the apt cache so that your resulting image is smaller. See the Dockerfile Best Practices for more details.

FROM microsoft/dotnet:2.0.0-sdk-jessie

ENV DEBIAN_FRONTEND noninteractive

# Install PowerShell pre-reqs
RUN apt-get update \
    && apt-get -y install \
        apt-utils \
        curl \
        apt-transport-https \
    && rm -rf /var/lib/apt/lists/*

# Install PowerShell
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
    && echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-jessie-prod jessie main" > /etc/apt/sources.list.d/microsoft.list \
    && apt-get update \
    && apt-get -y install \
        powershell \
    && rm -rf /var/lib/apt/lists/*

@WernerMairl feel free to close this issue if you feel your questions have been answered - thanks.

Thank you - sample up and running!
regards
Werner

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jamesstow picture jamesstow  路  6Comments

cypressious picture cypressious  路  5Comments

williamdenton picture williamdenton  路  6Comments

MichaelSimons picture MichaelSimons  路  5Comments

cnblogs-dudu picture cnblogs-dudu  路  3Comments