How to create Dockerfile in command prompt - docker

Tried to create Dockerfile but not working.I am getting below the error.
Error:
If i tried in command prompt:
C:\Users\admin\D1>touch Dockerfile
'touch' is not recognized as an internal or external command,
operable program or batch file.
If i tried in VS Code terminal:
PS C:\Users\admin\D1> touch Dockerfile
touch : The term 'touch' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and
try again.
At line:1 char:1
+ touch Dockerfile
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (touch:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
How to resolve this issue?

Try vi Dockerfile or vim Dockerfile, if it is installed, it may work

It is not something specific to Dockerfile it will be the same if you will create any file. The reason for that is that you are trying a Linux command in the windows command prompt. If you want to use these commands, you need to have a *nix based tool on your windows machine first. In Powershell, I think the equivalent of touch is New-Item.

Related

Adding printer on windows-docker

We are trying to dockerize some old powerbuilder batch jobs, and the existing code requires a ghostscript printer installed with the exact name (for the details see here)
Microsoft's documentation on Print Spooler in containers
states "apps that have a dependency on installing printer drivers into the host cannot be containerized because driver installation from within a container is unsupported"
I do not know if this is just a typo/missunderstanding, as why would any application want to install driver into host? I need it in the container, also is it only for the drivers or for the Printers as well?
Assuming this is only a typo/missunderstanding, and microsoft claims it can not be done in the container, the question is
could I do it through the host (and commit it into a new docker image)
could I do it through doccker file , using some MSI installer and run it there
is there any possibility to add a driver and printer in docker image ? (and if not it should be clearly stated)
Assuming this the above statement is not a typo/missunderstanding, than it should be possible to add printer to docker. For that we are using
FROM mcr.microsoft.com/windows:1909
and isolation is hyperv
We tried runnig this from the dockerfile
RUN powershell -command Add-Printer -Name \"Test Printer\" -DriverName \"Microsoft Print to PDF\" -PortName \"PORTPROMPT:\"
and get following errror
# InvalidData: (MSFT_Printer:ROOT/StandardCimv2/MS
# FullyQualifiedErrorId : HRESULT 0x80070006,Add-Printer
but I was not able to find anything meangifull for this error
I can list, rename and remove a printer but I can not add existing one, also if I execute
Get-PrintConfiguration "Microsoft Print To PDF"
I am getting
+ CategoryInfo : NotSpecified: (MSFT_PrinterConfiguration:ROOT/StandardCi...erConfiguration) [Get-PrintConfiguration], CimException
+ FullyQualifiedErrorId : HRESULT 0x8000ffff,Get-PrintConfiguration
so it seams there is something fishy with printers in the docker image.
Do you if there is any possibility to add printer to docker image / container?
thanks
almir
Probably your error in in the DockerFile command. You have to pass the hole command to the powershell and not just the Add-Printer.
I did not try it out, but i would do it like this:
RUN powershell -command "Add-Printer -Name \"Test Printer\" -DriverName \"Microsoft Print to PDF\" -PortName \"PORTPROMPT:\""
The question is quite old, but i would be curios to have a beedback :)

I can't create a global gitignore in my terminal. touch ~/.gitignore gives an error

I am trying to create a global .gitignore file with this command:
touch ~/.gitignore
but in my terminal (Cmder) gives this message: "touch: cannot touch '~/.gitignore': No such file or directory"
I have changed to windows terminal default (Command Prompt) and it says:
"'touch' is not recognized as an internal or external command, operable program or batch file."
What I am doing wrong or what can I do to solve this?
You are using linux syntax. Now, even though touch is not understood by cmd prompt, it is a command understood by cmder but expression ~/.gitignore is still linux way of saying things.
What you can do on cmd prompt, I guess also would work on cmder (edit: doesn't seem to work for cmder):
copy con "%USERPROFILE%\.gitignore"
[press F6 and enter after that]
For cmder, this could work:
touch "%USERPROFILE%\.gitignore"
This should help for windows terminal:
echo $null >> pot.txt
touch is linux command not windows command.
Below question should help a lot more :
https://superuser.com/questions/502374/equivalent-of-linux-touch-to-create-an-empty-file-with-powershell

Azure Cloud Shell Trouble running ps1 Scripts

In our Azure Cloud Shell, Powershell mode we can't run ps1 files. Although we are doing the same asin the MS Doc.
Any Suggestions, what am I doing wrong.
PS Azure:\> dir
Directory: Azure:/Shared PAAS – Test/StorageAccounts/tstoweuyptobi/Files/azureshellfiles/goal0402preprod/powershell
Mode Name
---- ----
. Build_goal.ps1
. Test goal_Files.ps1
. test.ps1
Azure:/Shared PAAS – Test/StorageAccounts/tstoweuyptobi/Files/azureshellfiles/goal0402preprod/powershell
PS Azure:\> ./test.ps1
./test.ps1 : The term './test.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ ./test.ps1
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (./test.ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Azure:/Shared PAAS – Test/StorageAccounts/tstoweuyptobi/Files/azureshellfiles/goal0402preprod/powershell
PS Azure:\>
The example below is from Microsoft Docs.
The trick is for the shell to be open in the location that the script is saved.
This will only work if your script doesn't use libraries that are stored on your local device. You may also need to import any modules needed, e.g. AzureAD
# change to your cloud drive fileshare
cd $HOME\clouddrive
# run the script
.\helloworld.ps1
Hello World!
The default directory for Cloud Shell does not seem to allow script running. Copy the script to "$HOME\clouddrive", change to that dir, then run it from there.

BitBucket and PowerShell

I am very new to BitBucket.Problem is that PowerShell does not recognize git command.What I am trying to do is to Clone.When i copy address to PowerShell and press Return this message shows:
The term 'git' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spellin
g of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:4
+ git <<<< clone https://B#bitbucket.org/B/firstrepository.git
+ CategoryInfo : ObjectNotFound: (git:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Does anyone know how to solve this?
Thanks in advance!
For posterity purposes I'm going to break out the hidden comment above by #bigyanshr into an answer:
Be sure to install the Git application as described on either this StackOverflow post or the Git 'Getting Started Installing Git' guide. This includes updating your PATH variable to include to your new Git installs 'Git/cmd' folder.

Microsoft.SystemCenter.VirtualMachineManager is not installed on this machine

I want to use get-vm command from powershell.
$my_vm = get-vm -Name MY_VM_NAME
Have error message that
The term 'get-vm' is not recognized as the name of a cmdlet, function,
script f ile, or operable program. Check the spelling of the name, or
if a path was incl uded, verify that the path is correct and try
again.
I found that I need to install Microsoft.SystemCenter.VirtualMachineManager
(how to run get-vm command on windows powershell)
Execute that:
PS C:\Windows\system32> Add-PSSnapin -Name
Microsoft.SystemCenter.VirtualMachineManager
Add-PSSnapin : The Windows PowerShell snap-in 'Microsoft.SystemCenter.VirtualMa
chineManager' is not installed on this machine.
At line:1 char:13
Do I really need to install that huge tool? I don't have enough space on my VM.
http://www.microsoft.com/en-us/download/details.aspx?id=10712
Is it another way to solve issue with get-vm?
Thanks!
You can look in to connecting to the machine that has VMM on it. You can use remoting to do this. You can find some more info about it here: http://windowsitpro.com/scripting/creating-remote-sessions-powershell-20?page=3

Resources