Trying to build a dockerfile for plex - docker

I am new to docker and using this as an example on how to learn. I am trying to create a dockerfile which would allow me to run plex on my windows sever. An awesome post created on the Plex forums describes how to perform the tasks using powershell, and so I wanted to see if it would be possible to create an image using these commands.
Here is what I have so far:
FROM microsoft/windowsservercore
RUN Get-ChildItem "$Env:SystemRoot\Servicing\Packages\*Media*.mum" | ForEach-Object { (Get-Content $_) -replace 'required','no' | Set-Content $_}
RUN Add-WindowsFeature Server-Media-Foundation;
RUN Invoke-WebRequest -OutFile Plex-Media-Server-1.12.3.4973-215c28d86.exe "https://downloads.plex.tv/plex-media-server/1.12.3.4973-215c28d86/Plex-Media-Server-1.12.3.4973-215c28d86.exe" -UseBasicParsing;
RUN .\plex.exe /quiet
RUN start 'C:\Program Files (x86)\Plex\Plex Media Server\Plex Media Server.exe'
EXPOSE 32400/tcp
I have removed comments for formatting.
So I have two questions,
first : this does not seem to run when using docker build -t test_plex .
I get the following error:
unable to prepare context: unable to evaluate symlinks in Dockerfile path: GetFileAttributesEx C:\Windows\System32\Dockerfile: The system cannot find the file specified.
second: using PowerShell would this all run in parallel? or is there some kind of wait command.
Any help/tips would be great, thanks for your time (sorry about long post)

It looks like you're running docker build -t test_plex . in C:\Windows\System32\. Move to an empty folder with just your Dockerfile and run the command again.
The . is the location of your build context, you can also change that location to a different path.
Keep in mind that when you run docker build -t test_plex . the "build context" or the directory that you're in when you run it is relevant to the build. Depending on your system all the files at the location you're running that command will be copied into the build vm.

Related

Powershell script from Docker Container

I am trying to run a simple powershell script from a docker container. The script is supposed to create an AD group.
The problem I am facing is that the ActiveDirectory module is not available, which is why commands such as "New-ADGroup" are not recognized.
This is my DockerFile
FROM packages.company.ch/icbuild/powershell
WORKDIR /app
COPY ./rabbitmq-adgroups-deploy/1.0/ /app
RUN pwsh -c "Get-PSRepository"
CMD [ "pwsh", "rabbitmq-adgroups.ps1"]
And this is my script "rabbitmq-adgroups.ps1"
Register-PSRepository -Default
Get-PSRepository
Install-Module ActiveDirectory
....
New-ADGroup -Name $SecurityGroup
....
And these are the log messages I get
When building the docker image, the moment it runs the "RUN pwsh -c "Get-PSRepository" command
WARNING: Unable to find module repositories.
When executing the powershell script, commands "Get-PSRepository", "Install-Module ..." and "New-ADGroup ..." respectively
WARNING: Unable to find module repositories.
Install-Package: No match was found for the specified search criteria and module name 'ActiveDirectory'. Try Get-PSRepository to see all available registered module repositories.
The term 'Add-ADGroupMember' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
I found out that it is not possible to run a powershell script that requires the Active Directory module from a Linux based Docker image, which is what I was doing.... At the end I decided to simply run the script from a Windows Machine without any Docker image whatsoever....

500 Internal Server Error Docker Hosted ASP.Net MVC web app (RESOLVED)

We have a ASP.Net MVC app and which works fine when we run even locally in debug mode from Visual Studio.
We have 4 Class library projects and one web api project. Following is my docker file:
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8 AS build
WORKDIR /app
# copy csproj and restore as distinct layers
COPY *.sln .
COPY xxxxx/*.csproj ./xxxxx/
COPY yyyyyy/*.csproj ./yyyyy/
# copy everything else and build app
COPY xxxxx/ ./xxxxx/
COPY yyyyy/ ./yyyyy/
RUN nuget restore
WORKDIR /app/GetThree
RUN msbuild /p:Configuration=Release
FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8 AS runtime
WORKDIR /inetpub/wwwroot
COPY --from=build /app/xxxxx/. ./
Once I build the docker file, everything compiles properly and build is successful also (all Nuget packages are restored) and I am able to create the container as well. But unfortunately whenever I try to browse to my web-app (I got the IP address of the container as this is windows base) but unfortunately I get HTTP 500 internal server error immediately. I have made sure that the HTTPERROR section is set for detailed error message.
As soon as I navigate to the ip address I get this 500 error and unfortunately not much is availble in the logs (Application or System) which will help me as to what the issue could be. Any help?
Following is the command I use to build and run the container:
docker build -f .\GetThree\Dockerfile -t threecms/cmsdocker:1.0
docker run --name threecms --rm -it -p 8100:80 threecms/cmsdocker:1.0
To browse the site I get the IP Address (using docker exec threecms ipconfig) and I browse it using: http://ipadress:8100
UPDATE 1:-
I created one more image from above image using following dockerfile ( urlrewrite is the URLREWRITE module install script)
FROM threecms/cmsdocker:1.0
WORKDIR C:/
Copy urlrewrite.ps1/ .
RUN "Powershell ./urlrewrite.ps1"
RUN Install-WindowsFeature Web-Mgmt-Service; \
New-ItemProperty -Path HKLM:\software\microsoft\WebManagement\Server -Name EnableRemoteManagement -Value 1 -Force; \
Set-Service -Name wmsvc -StartupType automatic;
URL REWRITE PS1 script:
New-Item c:/msi -ItemType Directory
Invoke-WebRequest 'http://download.microsoft.com/download/C/F/F/CFF3A0B8-99D4-41A2-AE1A-496C08BEB904/WebPlatformInstaller_amd64_en-US.msi' -OutFile c:/msi/WebPlatformInstaller_amd64_en-US.msi
Start-Process 'c:/msi/WebPlatformInstaller_amd64_en-US.msi' '/qn' -PassThru | Wait-Process
cd 'C:/Program Files/Microsoft/Web Platform Installer'; .\WebpiCmd.exe /Install /Products:'UrlRewrite2,ARRv3_0' /AcceptEULA /Log:c:/msi/WebpiCmd.log
Then I ran the container using following command:-
docker run --name threecms2 -d cmswindfeature/cmswinfeature:3.0
And now whenever I got to my application from browser it gives me the actual error msg which is:
Access to the path 'C:\inetpub\wwwroot\App_Data\TEMP\PluginCache\umbraco-plugins.373F7AAE388A.hash' is denied.
UPDATE:-2 RESOLVED
So to Resolve above error I ran the following Powershell script (To add required Permissions) and Boom I was able to access my site and its working now:-
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("IIS_IUSRS", "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")
$acl = Get-ACL "C:\inetpub\wwwroot"
$acl.AddAccessRule($accessRule)
Set-ACL -Path "C:\inetpub\wwwroot" -ACLObject $acl
You need to find out from the application pool for the website what is the identity it is running under (by default this is Application Pool Identity) and grant that the correct permissions. normally, it is IIS_IUSRS, you can try the following steps to solve the problem:
Right Click Folder-> go to Security Tab-> Click on Edit-> Click on Add-> Click on Advanced
-> Find Now-> Give Permission to IIS_IUSRS (Full Control)-> Click On OK-> Click On OK->
Click On Full Control in allow-> Click On OK.
Note: If above things are not working then try to give same permission to NETWORK,NETWORK SERVICE Users

Dockerfile capture output of a command

I have the following line in my Dockerfile which is supposed to capture the display number of the host:
RUN DISPLAY_NUMBER="$(echo $DISPLAY | cut -d. -f1 | cut -d: -f2)" && echo $DISPLAY_NUMBER
When I tried to build the Dockerfile, the DISPLAY_NUMBER is empty. But however when I run the same command directly in the terminal I get the see the result. Is there anything that I'm doing wrong here?
Commands specified with RUN are executed when the image is built. There is no display during build hence the output is empty.
You can exchange RUN with ENTRYPOINT then the command is executed when the docker starts.
But how to forward the hosts display to the container is another matter entirely.
Host environment variables cannot be passed during build, only at run-time.
Only build args can be specified by:
first "declaring the arg"
ARG DISPLAY_NUMBER
and then running
docker build . --no-cache -t disp --build-arg DISPLAY_NUMBER=$DISPLAY_NUMBER
You can work around this issue using the envsubst trick
RUN echo $DISPLAY_NUMBER
And on the command line:
envsubst < Dockerfile | docker build . -f -
Which will rewrite the Dockerfile in memory and pass it to Docker with the environment variable changed.
Edit: Note that this solution is pretty useless though, because you probably
want to do this during run-time anyways, because this value should depend on not on where the image is built, but rather where it is run.
I would personally move that logic into your ENTRYPOINT or CMD script.

Docker TICK Sandbox does not provide UDF Python functionality

I'm running this docker image to use the TICK Kapacitor locally.
The problem I face is that when I try to use User Defined Functions, e.g any of these examples I get the error message that /usr/bin/python2 does not exist.
I add the following to the kapacitor.conf:
[udf.functions]
[udf.functions.tTest]
prog = "/usr/bin/python2"
args = ["-u", "/tmp/kapacitor_udf/mirror.py"]
timeout = "10s"
[udf.functions.tTest.env]
PYTHONPATH = "/tmp/kapacitor_udf/kapacitor/udf/agent/py"
Further attempts from my side including altering the image used to build Kapacitor to install python works but the agent seems to fail to compile anyway.
Is there anyone who managed to get UDFs running using the Kapacitor Docker image?
Thanks
Docker image from the official repository: docker pull kapacitor does not have python installed inside. You can verify this by running shell in the container:
PS> docker exec -it kapacitor bash
and execute one of the command options:
$ python -VERSION
$ python: command not found
or
$ readlink -f $(which python) | xargs -I% sh -c 'echo -n "%:"; % -V'
$ readlink: missing operand
or
$ find / -type f -executable -iname 'python *'
void returns. And oppositely if python is available, commands return version and list of executable files
Note: Here and further all command snippets are given for Powershell on Windows. And all command snippets inside docker container are given for bash shell as Linux images are used.
Basicly, there is two options to get kapacitor image with python inside to execute UDFs:
Install the python in the kapacitor image, i.e. build new docker image from very kapacitor image.
Example could be found here:
Build a new verion of kapacitor image from one of the python official images
The second option is more natural as you get consistent python installation and keep efforts on doing work of installing python which already done by the docker community.
So following option 2 we'll perform:
Examine the Dockefile of the official kapacitor image
Choose an appropriate python image
Create new project and Dockerfile for kapacitor
Build and Check the kapacitor image
Examine Dockefile of official kapacitor image
General note:
For any image, the original Dockerfiles can be obtained in this way:
https://hub.docker.com/
-> Description Tab
-> Supported tags and respective Dockerfile links section
-> each of the tags is a link that leads to the Dockerfile
So for kapacitor everything is in the influxdata-docker git repository
Then in the Dockerfile we find that the image is created based on
FROM buildpack-deps: stretch-curl
here:
buildpack-deps
the image provided by the project of the same name https://hub.docker.com/_/buildpack-deps
curl
This variant includes just the curl, wget, and ca-certificates packages. This is perfect for cases like the Java JRE, where downloading JARs is very common and
  necessary, but checking out code isn't.
stretch
short version name of the OS, in this case Debian 9 stretch https://www.debian.org/News/2017/20170617
Buildpack-deps images are in turn built based on
FROM debian: stretch
And Debian images from the minimum docker image
FROM: scratch
Choose appropriate python image
Among python images, for example 3.7, you can find similar versions inheriting from buildpack-deps
FROM buildpack-deps: stretch
Following the inheritance, we'll see:
FROM buildpack-deps: stretch
FROM buildpack-deps: stretch-smc
FROM buildpack-deps: stretch-curl
FROM debian: stretch
In other words, the python: 3.7-stretch image only adds functionality to the Debian compared to the kapacitor image.
This means that we can to rebuild kapacitor image on top of the python image: 3.7-stretch with no risk or gaining incompatibility.
Docker context folder preparation
Clone the repository
https://github.com/influxdata/influxdata-docker.git
Create the folder influxdata-docker/kapacitor/1.5/udf_python/python3.7
Copy the following three files into it from influxdata-docker/kapacitor/1.5/:
Dockerfile
entrypoint.sh
kapacitor.conf
In the copied Dockerfile FROM buildpack-deps: stretch-curl replace with FROM python: 3.7-stretch
Be carefuly! If we work on Windows and because of scientific curiosity open the entrypoint.sh file in the project folder, then be sure to check that it does not change the end-line character from Linux (LF) to Windows variant: (CR LF).
   Otherwise, when you start the container later, you get an error:
or in the container log:
exec: bad interpreter: No such file or directory
or if you'll start debugging and, running the container with bash, will do:
$ root # d4022ac550d4: / # exec /entrypoint_.sh
$ bash: /entrypoint_.sh: / bin / bash ^ M: bad interpreter: No such file or directory
Building
Run PS> docker build -f. \ Dockerfile -t kapacitor_python_udf
Again, in case of Windows environment
If during the build execution an error occurs of the form:
E: Release file for http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease is not valid yet (invalid for another 9h 14min 10s). Updates for this repository will not be applied.
then your computer clock probably went out of sync and/or Docker Desktop incorrectly initialized the time after the system returned from sleep. See the issue)
To fix it, restart Docker Desktop and / or Windows settings -> Date and time settings -> Clock synchronization -> perform Sync
You can also read more here
Launch and check
Launching the container with the same actions as for the standard image. Example:
PS> docker run --name=kapacitor -d `
--net=influxdb-network `
-h kapacitor `
-p 9092:9092 `
-e KAPACITOR_INFLUXDB_0_URLS_0=http://influxdb:8086 `
-v ${PWD}:/var/lib/kapacitor `
-v ${PWD}/kapacitor.conf:/etc/kapacitor/kapacitor.conf:ro `
kapacitor
Check:
PS> docker exec -it kapacitor_2 bash
$ python -VERSION
$ Python 3.7.7
$ readlink -f $(which python) | xargs -I% sh -c 'echo -n "%:"; % -V'
$ /usr/local/bin/python3.7: Python 3.7.7

RUN command in Dockerfile not persisting from container to container

I am running yo in a Docker container and in my Dockerfile, I have the command RUN echo no | yo doctor. When yo runs for the first time, it asks for an answer to:
====================================================================
We're constantly looking for ways to make yo better!
May we anonymously report usage statistics to improve the tool over time?
More info: https://github.com/yeoman/insight & http://yeoman.io
==================================================================== (Y/n)
Every time, I create a new container, yo is asking me the same question again.
Since each container is being built using the same image and I am running echo no | yo doctor in my Dockerfile shouldn't it prevent yo from asking the question again?
Whenever I see a RUN using pipe, I try that command in a subshell (sh -c)
RUN sh -c 'echo no | yo doctor'
If it does not work, another workaround would be to include that command in a script, COPY the script and RUN it.

Resources