I'm running Windows 2019 Server with latest docker.
I need to start a windows container, and bind the current C: to Z: in the container, but this does not work:
docker run -v c:\:z:\ -it XXX cmd.exe
What's the correct syntax?
EDIT
Here's what I've tried
PS C:\Users\Administrator> docker run --mount 'type="bind",source="C:\",target="Z:\"' -it mcr.microsoft.com/windows/nanoserver:1809 cmd.exe
invalid argument "type=bind,source=C:\",target=Z:\"" for "--mount" flag: parse error on line 1, column 19: bare " in non-quoted-field
See 'docker run --help'.
PS C:\Users\Administrator> docker run --mount type=bind,source=C:\,target=Z:\ -it mcr.microsoft.com/windows/nanoserver:1809 cmd.exe
docker: Error response from daemon: hcsshim::CreateComputeSystem 9b4e6759c82a071453bf4449f18dbbb2bd90511651c146a6e561a45771e0548c: The parameter is incorrect.
PS C:\Users\Administrator>
Did you try with mount syntax?
using Powershell:
docker run --mount 'type="bind",source="C:\",target="Z:\"' myimage:latest
or
Without quotes:
docker run --mount type=bind,source=C:\,target=Z:\ myimage:latest
I just got this to work:
docker run -p 80:80 -v //e/testdata/:/opt/testdata imagetag
On host windows: e:\testdata
mapped in container: /opt/testdata
To access e:\testdata one needs to put a double slash before the drive letter, and no colon there. I am mapping into a linux container so that is a normal unix style path. The software inside the container was able to read and write the windows files.
Related
I'm using Windows-10 and using GitBash entering in the command
$ docker run -ti ubuntu:latest bash
And it gives me this error message
"the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'"
And so I placed in this command to switch to winpty
$ winpty docker.exe run -it --rm ubuntu:14.04 /bin/bash
And it still doesn't work. I know my ports are running correctly, and I installed ubuntu correctly.
At windows 10 and git bash this works for me:
winpty docker exec -it "CONTAINTER ID" sh
I'm very new to docker.
Also I'm using Docker for Windows (ie Image and Container are for Windows OS).
I'm trying to get a list of all the folders and subfolders to resolve another issue I'm having. I read several post and blogs and seems like I should be able to run
docker exec -it <container id> dir
To get the info as it is suppose to allow me to run commands against the container.
I even ran
docker exec -it f83eb1533b67 help
which gave me a list of commands (because no one tells what are acceptable 'commands'...) and it is listed. however I get the following message when I run DIR command
PS P:\docker\tmp\SqlServerSetup> `docker exec -it f83eb1533b67 dir`
container f83eb1533b671b4462b8a1562da7343185b2dd27e94ff360e0230969d432ec37 encountered an error during CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2)
[Event Detail: Provider: 00000000-0000-0000-0000-000000000000] extra info: {"CommandLine":"dir","WorkingDirectory":"C:\\","Environment":{"ACCEPT_EULA":"Y","attach_dbs":"[]","sa_password":"Pass1.4DBAs","sa_password_path":"C:\\ProgramData\\Docker\\secrets\\sa-password"},"EmulateConsole":true,"CreateStdInPipe":true,"CreateStdOutPipe":true,"ConsoleSize":[0,0]}
PS P:\docker\tmp\SqlServerSetup>
Please note: I don't want to persist a volume. Seems like that option is for people that are trying to reuse data.
UPDATE:
This is the statement that i'm using to create the container:
docker run -p 1433:1433 -e sa_password=Pass1.4DBAs -e ACCEPT_EULA=Y -p 11433:1433 --name sqlTraining --cap-add SYS_PTRACE -d microsoft/mssql-server-windows-developer
It works fine. Container is created, but I want to view the filesystem within that container.
For Windows containers, prefix the command with the command shell (cmd) and the /c parameter. For example:
docker exec <container id> cmd /c dir
This will execute the dir command on the specified container and terminate.
Try running:
docker exec -it <container id> sh
to start the interactive shell console. This should help you with debugging.
I have script that load a database into RAM and print the adress of the first data into a file (db_REGISTER), and I want to run it inside a docker. This script works fine when it is launched inside a bash after launching the docker with -it
$ docker run -it --env-file $FILE -v $wkp:/app dev_machine
$$ /app/scripts/loadBase.sh
db_REGISTER
<some random number>
However when I launch the same script with docker run directly, the script works but the adress printed is always 0, and I cannot use the database afterward.
$ docker run -it --env-file $FILE -v $wkp:/app dev_machine /app/scripts/loadBase.sh
db_REGISTER
0
Does that mean that the second command does not have access to a persistant adress in the RAM ? What should I do to correct that ?
EDIT : After some advice, I tried to tweak the --ipc setting. Using --ipc="host" made it work. I guess this was a problem of shared RAM
You could try to mount your file inside the Docker container before executing the command:
docker run -it --env-file $FILE -v $PWD/scripts:/t -w /t dev_machine loadBase.sh
I run docker in my win10, but use -v params has a error.
docker run --privileged=true -d --name=ubuntu14.04 -v e:/docker/data:/data ubuntu /bin/bash
error:
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused "exec: \"C:/Program Files/Git/usr/bin/bash\": stat C:/Program Files/Git/usr/bin/bash: no such file or directory".
When I ls this path just like error path pic:
If possible, try the same command in a regular DOS session, instead of a git bash.
That will avoid the git bash session to automatically resolve /bin/bash to C:/Program Files/Git/usr/bin/bash, which won't be known at all by the ubuntu container.
The OP confirms this is working, provided the following options are added:
--attach=STDIN
--privileged=true
winpty docker run -i -t test1 ./bin/sh
Will work on Windows OS.
Add two slashes before bin/sh to turn off GitBash's automatic path conversion.
docker run --privileged=true -d --name=ubuntu14.04 -v e:/docker/data:/data ubuntu //bin/bash
or if you're trying to attach to a running container
docker attach -it ubuntu //bin/bash
Input:
- There is Windows machine with Docker Toolbox installed.
- There is a shell script file baz.sh which calls py2dsc-deb.
Problem: py2dsc-deb is not available on Windows.
As I understand correctly, I can pull some Linux distro image from Docker repository, create a container and then execute shell-script file and it will run py2dsc-deb and do its job.
I have pulled:
debian - stretch-slim - 3ad21 - 3 weeks ago - 55.3MB
Now
How do I run my script using debian, something like: docker exec mycontainer /path/to/test.sh?
Running docker --rm debian:stretch-slim does nothing. Doesn't it suppose to run Debian distro at docker-machine ip?
I have tried to keep the container up using docker run -it debian:stretch-slim /bin/bash, then run the script using docker exec 1ef5b ./build.sh, but getting
$ docker exec 745 ./build.sh
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: \"./build.sh\": stat ./build.sh: no such file or directory"
Does it mean I can't run external script and has to always pass it inside the Docker?
You can execute bash command inside your container by typing
docker exec -ti -u `username` `container_name` bash -c "cd /path/to/ && ./test.sh"
lets say your container name is test_buildbox, you are root and your script stays inside /bin/test.sh You can call this script by typing
docker exec -ti -u root test_buildbox bash -c "cd /bin/ && ./test.sh
Please check if you have correct line endings in your .sh scripts (<LF>) when you built Docker image on Windows.