Bunch of docker links and scripts

28 Aug 2017

docker

Bunch of docker links and scripts

Setting up a Docker Hub registry mirror on a Synology NAS

Moving the Docker image directory on Windows and deleting old images folder with magic utility

Create custom local domains for the docker images

function Update-DockerHosts()
{
    $processfile=$args[0]
    $defaultHostsFile = "C:\Windows\System32\drivers\etc\hosts"

    if ([string]::IsNullOrEmpty($processfile))
    {
        $processfile = $defaultHostsFile
    }
    if (-not (Test-Path $processFile))
    {
        Echo "File $processfile not found"
        return
    }
    $tmpfile=$processFile+".tmp"

    #
    # for all running docker containers
    #
    $containers = docker ps -q
    Foreach ($container in $containers)
    {
        Echo $container
        #
        # Extract the servicename and ipaddress
        #
        $servicename = (docker inspect --format '{{ .Config.Image }}' $container).split("/")[-1]
        $ipaddress = docker inspect --format '{{ .NetworkSettings.Networks.nat.IPAddress }}' $container

        Echo $servicename
        Echo $ipaddress

        #
        # if there is a service name and ipaddress
        #
    if ((-not ([string]::IsNullOrEmpty($servicename))) -And (-not ([string]::IsNullOrEmpty($ipaddress))))
    {       
            # remove the service name from the process file, and add it again
            get-content $processfile | select-string -notmatch ".*$servicename.*" | % {$_.ToString()} | echo > $tmpfile
            echo "$ipaddress`t$servicename.local" >> $tmpfile
            mv -Force $tmpfile $processfile
        }
    }
}

Docker run on IIS

FROM microsoft/aspnet:4.6.2

COPY  obj/Publish/Website-Test /inetpub/wwwroot

RUN ECHO 'start-service aspnet_state' >> start.ps1

RUN ECHO 'C:\ServiceMonitor.exe w3svc' >> start.ps1

ENTRYPOINT .\start.ps1

EXPOSE 80

Docker run on custom port on IIS

FROM microsoft/aspnet:4.6.2

WORKDIR /Website-Test

COPY  bin/Publish/ .

SHELL ["powershell"]

RUN Import-module IISAdministration; \
    New-IISSite -Name "Website-Test" -PhysicalPath C:\Website-Test -BindingInformation "*:8000:"

EXPOSE 8000

Build and publish the dotnet core app for docker deployment

msbuild /p:DeployOnBuild=true /p:PublishProfile=Docker.pubxml

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.