I want to run an exe file on window container using Docker. My exe accepts parameters. New file gets created in predefined directory
ie:- Test.exe -f1=file1.txt -f2=file2.txt
**Output** :
Writing file file1.txt
Successfully created file file1.txt
Writing file2 file2.txt
Successfully created file file2.txt
Enjoy!!
My docker file looks like below
FROM microsoft/aspnet:3.5-windowsservercore-10.0.14393.1715
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
Copy Test.exe ./TestFolder/
WORKDIR /TestFolder
ENTRYPOINT ["Test.exe"]
CMD ["f1=file1.txt","f2=file2.txt"]
I build the image and run the container
docker build -t image1 .
docker run -it image1
Once the container runs I get the exact above output but when I login to container machine using scripts, I don't see any file created in the predefined path.
Am I missing out anything ? Is this the correct way to run exe file on windows base image?
Any advice is appreciated. Thanks
Found out that the exe was running fine and file was created.
The way I logged in to container was wrong
Use
docker exec -it containername powershell
docker run -it --entrypoint powershell imagename --> Runs new instance of image not existing
Related
I just want to rename a few files, without overriding the commands inside the wordpress image that the docker is pulling in.
Inside the docker-compose.yml I tried using 'command' and 'entrypoint' to run bash commands, both basically interrupt what's happening inside the image and it all fails.
you have three main ways to run a command after the container starts:
with docker exec -d someContainer some command from the command line,
with CMD ["some", "command"] from your Dockerfile
with command: some command from a docker-compose file
if none of these is working for you, probably, you are doing something wrong. A common mistake is using multiple command in your docker-compose file, like so:
version: '3.8'
services:
someService:
command: a command
command: another command
this doesn't work, because the last command overrides the commands above, what you should do is concatenate the commands:
version: '3.8'
services:
someService:
command: a command && another command
take a look at this question.
edit: one thing i forgot to include is that the same behavior above is true to CMD in your Dockerfile, you can't do this:
CMD ["some", "command"]
CMD ["another", "command"]
instead, you should concatenate the commands, just like the docker-compose:
CMD ["some", "command", "&&", "another", "command"]
but this is very boring if you have a lot of commands, so an alternative is to use a shell script with all the commands you need and execute it in your Dockerfile:
#!/bin/sh
# bash file with your commands
run wordpress && rename files && do something else
# later in your Dockerfile
CMD ["sh", "/path/to/file.sh"]
see this question
As you haven't provided any code it's hard to say, but also, maybe you can use RUN command to rename as the last command(just before the CMD if you are using it) in your Dockerfile to rename these files at build time(what IMHO makes more sense because this is kind of thing you should do when you are building your images). So if you want more help, please, include your code too.
The new docker compose v2 is supposed to allow to run docker compose, using the space to replace the dash, directly. But if I put it in a .sh file and run it, it can't recognize the command. But I can directly run docker compose from command line. Also if I replace docker compose with docker-compose in the script, it worked. So what am I missing, to make docker compose work in bash script?
Turns out the probable reason of this is the bash file's EOL issue. The file was originally created on Windows and then copied to Linux.
When testing API using locust distributed mode without UI in docker. The distribution.csv, requests.csv are getting generated but the failures.csv and expection.csv are not getting generated but the requests.csv show failures as given below.
"Method","Name","# requests","# failures","Median response time","Average response time","Min response time","Max response time","Average Content Size","Requests/s"
"POST","/api/something/something",197009,56,470,559,78,156714,1,436.31
Can you please help.
The problem is that file need to be written to a folder that it has permission to, and a volume that is mounted to your host. If you add a mounted folder before the file name, it should work. For example:
Docker file:
# Set base image
FROM locustio/locust
ADD locustfile.py locustfile.py
Docker create Command:
docker build -t mykey/myimage:1.0 .
Docker run command (on Windows, replace with %CD% with $pwd on linux):
docker run --volume "%CD%:/mnt/locust" -e LOCUSTFILE_PATH=/mnt/locust/locustfile.py -e TARGET_URL=https://example.com -e LOCUST_OPTS="--clients=10 --no-web --run-time=600 --csv=/mnt/locust/output" mykey/myimage:1.0
The files will now write to the same folder where locustfile.py is located.
I'm trying to setup an automated build container in Windows(host and guest). Right now I'm having problems executing a simple powershell inside the container. I've done the following:
Created this DockerFile:
# escape=`
FROM microsoft/windowsservercore
SHELL ["cmd", "/S", "/C"]
CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]
Executed this build command:
docker build -t test:latest .
Started the docker with this command:
docker run test
The PowerShell prints this and the container exits:
PS C:\>
D:\repo\docker\Teste
Tried again with this command:
docker start d05ee -ai
The PowerShell prints the same output:
PS C:\>
D:\repo\docker\Teste
I wish to use the container interactively in a first moment to validate the tools I will install on it, but I'm not able to do that. I don't now which error is blocking me to do it and that is my question.
Obs1: The powershell in a windows cmd with the same parameters work fine.
Obs2: I've based my DockerFile on the one in this tutorial.
Obs3: Running this works fine:
docker run -it microsoft/windowsservercore powershell -NoLogo -ExecutionPolicy Bypass
Therefore I presume the problem is on the image generation.
you need to run your container with the -it switch. this will make you container interactive, so you can poke around
docker run -it test
I have a powershell script in host which copy some files and starts the container.
#Copy File
docker cp "D:\addApplication.ps1" website:/inetpub/wwwroot/
#Start Container
docker start website
Write-Host 'Process has started'
#Execute Container
docker exec -ti website powershell
#Run Script
Invoke-Expression "C:\inetpub\wwwroot\addApplication.ps1"
Second last command executes fine but last command will only execute when I exit the container session and returns error(File Not Found which is because it finds that file on host)
Question: Is there anyway I can execute the command in container session from the script. Or execute any command from script in any process(confused)
Any help is appreciated.
Thanks
Do not use the -ti flags to start an interactive session, just execute the script directly via the docker exec command
docker exec website powershell -command "C:\inetpub\wwwroot\addApplication.ps1"