I am using docker toolbox v17.03 in Windows 10 Home. I am playing with flask app from python slim. I tried to mount the current directory to app and tried ${PWD} and %cd% like below.
docker container run -it -p 5000:5000 -e FLASK_APP=app.py --rm -e FLASK_DEBUG=1 -v %cd%:/app web1
==> Got the error saying invalid characters
docker container run -it -p 5000:5000 -e FLASK_APP=app.py --rm -e FLASK_DEBUG=1 -v ${PWD}:/app web1
==> Neither error nor working
The second form ${PWD} would be working in a Powershell session.
If it still says "invalid characters", that means:
the %cd% is not resolved as an absolute path
it includes characters that are not in [a-zA-Z0-9][a-zA-Z0-9_.-], making it inelligible for a volume name.
Double-check what %cd% returns, and if there is any special non-ascii character in it (or spaces)
Related
I hope someone can help me to locate the issue. I created a SQL Server 2019 container using this code:
docker run --name SQL19 -p 1433:1433 -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=zzzzz258*" -v /SqlDockerVol/userdatabase:/userdatabase -v /SqlDockerVol/sqlbackups:/sqlbackups -d mcr.microsoft.com/mssql/server:2019-lates
The problem I am having is the container not showing the files I saved in the /sqlbackups folder.
I am using Ubuntu 20.04.
I logged into the SQL19 container like this:
docker exec -it SQL19 /bin/bash
then issued ls sqlbackups to confirm.
Do I need to set any permission on the host folder. I am not familiar with Linux.
Thanks
I suspect you need to pass absolute path to your folder:
/SqlDockerVol/userdatabase
is it full absolute path?
If it is relative change it to:
$(pwd)/SqlDockerVol/userdatabase
Please check this Docker shared folder with Linux
And technically you need something like:
docker run --name SQL19 -p 1433:1433 -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=zzzzz258*" -v $(pwd)/SqlDockerVol/userdatabase:/userdatabase -v $(pwd)/SqlDockerVol/sqlbackups:/sqlbackups -d mcr.microsoft.com/mssql/server:2019-lates
I am trying to run the following command
docker run -p 3000:3000 -v/app/node_modules -v $(pwd):/app 2ef0206fcf99
I am getting the following error
docker: Error response from daemon: create $(pwd): "$(pwd)" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.
How can I fix the issue?
1) Using Windows Powershell, following works for me:
docker run --rm -it -v ${pwd}:/mydir nginx:latest bash
Note:
I have used curly braces around pwd instead of small braces
2) Using Git Bash, following syntax should work:
winpty docker run --rm -it -v "/$PWD":/mydir nginx:latest bash
Note:
If you do not use winpty at the start of the command, you will get error message: the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'
Also notice the / before $PWD. Without the /, it will not throw error but i noticed that it didn't mount the directory.
I also had the same issue on windows make sure that you put "$PWD" something like this so your command should be something like this
docker run --rm -it -p 3000:3000 -v "$PWD:/app" 2ef0206fcf99
or another way is
docker run --rm -it -p 3000:3000 --volume="$PWD:/app" 2ef0206fcf99
I am trying to reproduce steps to create an Ubuntu based image + nginx, described there:
https://www.howtoforge.com/tutorial/how-to-create-docker-images-with-dockerfile/
My host machine is Windows.
The image is built, then I have created d:\webroot folder on host, index.html file inside and try to run
docker run -v /d/webroot:/var/www/html -p 80:80 --name doom nginx_image
standard_init_linux.go:211: exec user process caused "no such file or directory"
What may be the reason and how to fix it?
The issue is with the start.sh script which is loaded from Windows. Excerpt below:
#!/bin/sh
/usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
You need to change the change line ending from CRLF to LF for the start.sh.
And then run: docker run -v /d/webroot:/var/www/html -p 80:80 --name doom nginx_image
I'm new to Docker, i'm using the Toolbox version for dockers. I try the following command:
docker run -it --name myflask1 -p 192.168.99.100:5000 -v ${PWD}:/app python:3.7 bash
The following message appear:
invalid publish opts format (should be name=value but got 'docker-machine')
What is the solution?
Your -p option looks bad. Format should looks:
-p ip:hostPort:containerPort,
-p ip::containerPort,
-p hostPort:containerPort,
-p containerPort.
I would like to run this command:
docker run docker-mup deploy --config .deploy/mup.js
where docker-mup is the name the image, and deploy, --config, .deploy/mup.js are arguments
My question: how to mount a volume such that .deploy/mup.js is understood as the relative path on the host from where the docker run command is run?
I tried different things with VOLUME but it seems that VOLUME does the contrary: it exposes a container directory to the host.
I can't use -v because this container will be used as a build step in a CI/CD pipeline and as I understand it, it is just run as is.
I can't use -v because this container will be used as a build step in a CI/CD pipeline and as I understand it, it is just run as is.
Using -v to expose your current directory is the only way to make that .deploy/mup.js file inside your container, unless you are baking it into the image itself using a COPY directive in your Dockerfile.
Using the -v option to map a host directory might look something like this:
docker run \
-v $PWD/.deploy:/data/.deploy \
-w /data \
docker-mup deploy --config .deploy/mup.js
This would map (using -v ...) the $PWD/.deploy directory onto /data/.deploy in your container, set the current working directory to /data (using -w ...), and then run deploy --config .deploy/mup.js.
Windows - Powershell
If you're inside the directory you want to bind mount, use ${pwd}:
docker run -it --rm -d -p 8080:80 --name web -v ${pwd}:/usr/share/nginx/html nginx
or $pwd/. (forward slash dot):
docker run -it --rm -d -p 8080:80 --name web -v $pwd/.:/usr/share/nginx/html nginx
Just $pwd will cause an error:
docker run -it --rm -d -p 8080:80 --name web -v $pwd:/usr/share/nginx/html nginx
Variable reference is not valid. ':' was not followed by a valid variable name character. Consider using ${} to
delimit the name
Mounting a subdirectory underneath your current location, e.g. "site-content", $pwd/ + subdir is fine:
docker run -it --rm -d -p 8080:80 --name web -v $pwd/site-content:/usr/share/nginx/html nginx
In my case there was no need for $pwd, and using the standard current folder notation . was enough. For reference, I used docker-compose.yml and ran docker-compose up.
Here is a relevant part of docker-compose.yml.
volumes:
- '.\logs\:/data'