I'm following this tutorial that uses Docker. When I tried to run Docker (inside the run.sh script):
docker run \
-p 8888:8888
-v `pwd`/../src:/src \
-v `pwd`/../data:/data -w /src supervisely_anpr \
--rm \
-it \
bash
I got the error:
docker: invalid reference format.
I spent 2 hours and I can't really understand what's wrong. Any idea really appreciated.
In powershell you should use ${pwd} instead of $(pwd)
The first argument after the "run" that is not a flag or parameter to a flag is parsed as an image name. When that parsing fails, it tells you the reference format, aka image name (but could be an image id, pinned image, or other syntax) is invalid. In your command:
docker run -p 8888:8888 -v `pwd`/../src:/src -v `pwd`/../data:/data -w /src supervisely_anpr --rm -it bash
The image name "supervisely_anpr" is valid, so you need to look earlier in the command. In this case, the error is most likely from pwd outputting a path with a space in it. Everything after the space is no longer a parameter to -v and docker tries to parse it as the image name. The fix is to quote the volume parameters when you cannot guarantee it is free of spaces or other special characters.
When you do that, you'll encounter the next error, "executable not found". Everything after the image name is parsed as the command to run inside the container. In your case, it will try to run the command --rm -it bash which will almost certainly fail since --rm will no exist as a binary inside your image. You need to reorder the parameters to resolve that:
docker run --rm -it -p 8888:8888 -v "`pwd`/../src:/src" -v "`pwd`/../data:/data" -w /src supervisely_anpr bash
I've got some more details on these two errors and causes in my slides here: https://sudo-bmitch.github.io/presentations/dc2018/faq-stackoverflow-lightning.html#29
I had the same issue when I copy-pasted the command. Instead, when I typed-in the entire command, it worked!
Good Luck...
I ran into this issue when I didn't have an environment variable set.
docker push ${repo}${image_name}:${tag}
repo and image_name were defined but tag wasn't.
This resulted in docker push repo/image_name:.
Which threw the docker: invalid reference format.
I had a similar problem.
Issue I was having was $(pwd) has a space in there which was throwing docker run off.
Change the directory name to not have spaces in there, and it should work if this is the problem
I was having the same problem on Linux. That was because of directory names contained spaces. I fixed it by using "$(pwd)/path/to/go" instead of $(pwd)/path/to/go
I was executing the whole command in one line, as it was mentioned as such
$ docker run --name testproject-agent \
-e TP_API_KEY="REPLACE_WITH_YOUR_KEY" \
-e TP_AGENT_ALIAS="My First Agent" \
testproject/agent:latest
But its supposed to be a multiline command, and I copied the command line by line and pressed enter after every line and bam! it worked.
Sometimes when you copy off of the web, the new-line character gets omitted, hence my suggestion to try manually introducing the new line.
For others come here:
If you happen to put your docker command in a file, say run.sh, check your line separator. In Linux, it should be LR, otherwise you would get the same error.
In my case, the command was like this
docker run -d --name kong-database \
--network=kong-net \
-p 5432:5432 \
-e "POSTGRES_USER=kong" \
-e "POSTGRES_DB=kong" \
-e "POSTGRES_PASSWORD=kongpass" \
postgres:9.6
I was trying to copy everything in a single line including slash (\) and was getting the following error
docker: invalid reference format.
The slash (\) in the command indicates the next line, so if you are trying to run the complete command in a single line just remove the slash (\), it worked for me
Thanks :)
I was using a very generic command
docker build .
It turned out that I needed to just specify the tag name otherwise there was no name to use
docker build . -t image_name
And then it worked.
Found that using docker-compose config reported what the problem was.
In my case, an override compose file with an entry that was overriding nothing.
I removed () and worked for me like this
docker run -d -v $pwd/envoy.yaml:/etc/envoy/envoy.yaml:ro -p 8080:8080 -p 9901:9901
I am using windows 10
This also happens when you use development docker compose like the below, in production. You don't want to be building images in production as that breaks the ideology of containers. We should be deploying images:
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
Change that to use the built image:
web:
command: /bin/bash run.sh
image: registry.example.com:9000/dyndns_api_web:0.1
ports:
- "8000:8000"
I was getting the same issue while using $(pwd) through powershell, I replaced it with ${pwd} and it worked for me.
Following are the details for the same:
PS C:\Users\Systems\git\mastery\dockerfile> docker container run -d --name nginx -p 8080:80 -v $(pwd):/usr/share/nginx/html nginx
docker: invalid reference format.
See 'docker run --help'.
PS C:\Users\Systems\git\mastery\dockerfile> docker container run -d --name nginx -p 8080:80 -v ${pwd}:/usr/share/nginx/html nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
Digest: sha256:25975292693bcc062becc20a1608936927f9950a42fb4474088f6292dacd4ec9
Status: Downloaded newer image for nginx:latest
f6ff08ed3b73095e85474bd2f248a7cae6b5bcdb53e12e4824d235df3cd268aa
In my case the problem is in the full path to folder with repo where I use terminal & docker. I was something like this:
repo (1)/repo/
so rename folder to
repo/repo
and it will help
Sometimes the problem is an additional whitespace at the end of line.
Bad: ðŸ˜
-v "$(pwd)/../src:/src" \
Spaces at the end!
Good: 🤩
-v "$(pwd)/../src:/src" \
Only newline after the slash!
Bonus hint: Some editors (like VSCode) give a different color to a slash followed with a whitespace.
One of the problems I had is that in my configs of skaffold config list -a, my default-repo was set to https://docker-registry.url.com as seen below:
kubeContexts:
- kube-context: minikube
default-repo: https://docker-registry.url.com
but instead, the correct way should have been without https://:
kubeContexts:
- kube-context: minikube
default-repo: docker-registry.url.com
Run it on CMD instead of PowerShell if you are using Windows.
In case anyone else hits it, yet another variant that results in this error is caused by a trailing / or \ on your path specification.
i.e. -v c:\mystuff:c:\mappedfolder works
but: -v c:\mystuff\:c:\mappedfolder does not
Where there is the extra "\" at the end of mystuff
So in my case, the problem was that the command was "illegal", aka. in a format that was not supported, which was the last thing expected since I found it in the official documentation, but it is what it is. Make sure you are using the right command.
Another case when this can show up is when you're missing the image to be run.
Just a heads-up: if any folder of you path has a space in it, remove it. For example if one of the folder's name is my folder, change it into my-folder.
If you run the script in windows PowerShell you need to replace $(pwd) to ${pwd} with curly brackets.
Remove the \ and just write your command continuously.
Write it like this
docker run -p 8888:8888 -v `pwd`/../src:/src -v `pwd`/../data:/data -w /src supervisely_anpr --rm -it bash
instead of
docker run \
-p 8888:8888
-v `pwd`/../src:/src \
-v `pwd`/../data:/data -w /src supervisely_anpr \
--rm \
-it \
bash
Related
I am very new to Docker so please forgive any technical wording mistakes I make regarding this.
I am trying to get a very basic "Hello World!" php script to run through a localhost docker container. I am trying to run this script to test out this image that contains php and oracle: https://hub.docker.com/r/silencesys/php-oci8
I pulled it using this command: docker pull silencesys/php-oci8
Then I tried to run it with numerous commands, some of them giving me this:
[16-Jun-2022 17:57:12] NOTICE: fpm is running, pid 1
[16-Jun-2022 17:57:12] NOTICE: ready to handle connections
And then some of them give a random string of letters and numbers. I don't know what it refers to but I know that it means that it is running the container. When I open the container's terminal and run 'ls' I can see my index.php file. I can even run 'cat index.php' and see that it contains the proper code in there to run "Hello World!" I will even include the code in here as a sanity check:
<?php
echo "Hello World!";
?>
But everytime that I open up the localhost in my browser, I get this:
This page isn’t working right now
localhost didn’t send any data.
ERR_EMPTY_RESPONSE
I have tried so many variations of this base docker run command that I found here:
docker run -d -p 80:80 --rm --name temp-container -v "$PWD":/var/www/html silencesys/php-oci8
Any help is greatly appreciated!
The docker image you are referring to does contain PHP, but it does not contain a web server.
Servers that serve web pages using PHP consist of a webserver software, that accepts HTTP-requests and communicates to PHP running in the background if needed. It can be thought of an intermediary between the Browser and PHP, and if it is missing the browser cannot access your PHP script.
I haven't found an image that could help you right away, however I stumbled upon this, and it tells that for your usecase you should go for a PHP image that has Apache included (i.e. the name will contain apache in the tag).
The way I solved this was by using this image in conjunction with the image I was using in the Question. Here is a step by step guide of what I did:
Create folder in home/[username] directory
docker pull soivangoi/nginx-php-adminer-oci8
docker pull silencesys/php-oci8
docker run -dit -p 8080:80 soivangoi/nginx-php-adminer-oci8 -v "$PWD":/var/www/ silencesys/php-oci8
4.1. If that doesn't work try this "docker run -d -it -p 8080:80 -v "$PWD":/var/www/ silencesys/php-oci8"
docker run -it -p 8080:80 --rm --name test-container -v "$PWD":/var/www/ soivangoi/nginx-php-adminer-oci8
Bash into the container. Either by command line or by clicking the terminal button on the container.
cd to where your php code is stored.
Run it!
Just make sure that whatever network you are on has access to the oracle database or else it will not let you run your code still.
I am a beginner in using Docker, and I am trying to run docker from php, specifically I need to run openface code. I used the command lines provided here https://cmusatyalab.github.io/openface/setup/ to make sure that docker is running on my pc correclty and it works. but now I need to call it from PHP, I wrote the same commands in batch file as follows
docker run -p 9000:9000 -p 8000:8000 -t -i bamos/openface /bin/bash
cd /root/openface
./demos/compare.py images/examples/{lennon*,clapton*}
pause
and tried to execute it in php by calling
echo shell_exec ("test.bat");
but when I run the batch file directly, only the first line is executed. as it seems the next command is not being executed inside the docker container.
how can I make all commands execute?
any help will be very much appreciated,
thank you
The problem is the first bash won't exit before you exit it and the rest of the commands are interpreted by host bash.
What you need is that your work is done and then you get inside a bash (inside the container)
docker run -p 9000:9000 -p 8000:8000 -t -i bamos/openface /bin/bash -c "cd /root/openface && ./demos/compare.py images/examples/{lennon*,clapton*} && exec bash"
First "bash -c" is to execute the commands and last command exec bash override the main bash and gives you a shell
My ultimate goal is to run different versions of PHP on my local computer for testing.
I believe Docker is the best way to accomplish this.
I have been able to get a container with Apache and PHP running via this tutorial: https://github.com/tutumcloud/apache-php
But the issue is that I cannot mount a volume so that I can edit local files and view them on the docker container.
Here are my steps in terminal running in the same directory as the docker file:
docker build -t tutum/apache-php .
docker run -d -p 8080:80 tutum/apache-php -v /Users/user-name-here/apache-php/sample:/app/
The error I get back is:
docker: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"-v\": executable file not found in $PATH".
I'm on OSX - El Captain, just installed latest version of Docker and Docker tools.
The basic format of the docker run command is:
docker run [<options>] <image> [<command>]
In this case, your image is tutum/apache-php, and the run command is being parsed like this:
docker run -d -p 8080:80 tutum/apache-php -v /Users/user-name-here/apache-php/sample:/app/
docker run
options: -d -p 8080:80
image: tutum/apache-php
command: -v /Users/user-name-here/apache-php/sample:/app/
This is the source of your error.
exec: "-v": executable file not found in $PATH
Since the command begins with -v, it will try to locate and execute that command. Of course, it doesn't exist, so you will get this error.
The fix is simply to move the -v option and its argument to the proper place.
docker run -d -p 8080:80 -v /Users/user-name-here/apache-php/sample:/app/ tutum/apache-php
I'm trying to use Docker on Windows through Docker Toolbox, but I'm struggling to make it work. I've pulled Docker PHP image. For example, this simple ls command fails:
$ docker run -it --rm -v /$(pwd):/home/projects php:7.0-cli ls -l /home/projects
ls: cannot open directory /home/projects: Operation not permitted
Also, any other operation within the mounted volume fails with Operation not permitted message.
Looks like a path issue with the volume mapping. Docker Toolbox uses Git Bash for the terminal, which uses /c as the root of the C: drive:
$ echo $(pwd)
/c/Users/elton
So your /$(pwd) is prepdening an extra forward slash. I'd try with a fully-qualified path first just to verify:
$ docker run -it --rm -v /c/projects:/home/projects php:7.0-cli ls -l /home/projects
I'm testing the official image docker PHP:
docker run -d -p 8000:80 --name test php:7-apache
Then, I test http://localhost:8000, I find this:
Forbidden
You don't have permission to access / on this server.
What am I doing wrong?
docker run -d -p 8000:80 --name test php:7-apache -v "$PWD":/var/www/html
Go to your project folder and run the above command or replace $PWD with your project directory. -v will sync your project to the docker container.
Or create a Docker file and use copy to run your project within the container.
Any one of the above will solve your problem.
The probable reason for the error is the fact that there is no project to render.
There's no hello world included with this image, /var/www/html/ is empty so there's no content to view. You need to bundle your own code in as the page on this image instructs:
We recommend that you add a custom php.ini configuration. COPY it into
/usr/local/etc/php by adding one more line to the Dockerfile above and
running the same commands to build and run:
FROM php:7.0-apache
COPY config/php.ini /usr/local/etc/php/
COPY src/ /var/www/html/
If you don't have files, it's behavior is normal.
But if you have, probabily is problem of permissions.
Error 403 is likely permission problem.
Inside container, run command:
$ ls -lsh
If letter 'r' (read) don't, you can try:
$ chmod +r <file>
Edit/add the .htaccess rewrite rule:
.htaccess
...
RewriteRule /
...