docker run -> command not found? - docker

I previously create an image with the command
docker build -t test .
but when I tried to run it with this command in the console
docker run -p 8080:9552 test
I get this error
docker run -p: command not found
any clue?

Related

How to solve buildah run error: container not known?

So I build container using buildah bud:
buildah bud -t ${imageFullName()} -f ${componentName}/DockerfileTests ${buildArgsStr} ${componentName}
But then, when I try to run a command inside this container:
buildah run ${componentName} -- python3 -m pytest src/test_models.py
it returns error reading build container: container not known . How can I solve this issue?
In this case, my first command make an image, not a container.
To create a container from this image, i have to run command:
buildah from ${imageFullName()}
Now, when you've created a container you can look for it's name by using a command which displays all containers that are avalable now:
buildah containers
And after getting the name of the container you can successfully run:
buildah run ${containerName} -- ...your command...

Error running interactive Docker on git-bash (prefixing winpty doesn't help)

I'm new to Docker.
I have a simple DockerFile:
FROM ubuntu:12.04
CMD echo "Test"
I built the image using the docker build command (docker build -t dt_test .).
All that I want to do is run the docker image interactively on Git bash. The path in git has been set up to include the docker toolbox.
When I run the interactive docker run command: "docker run -it dt_test"
it gives me an ERROR:
the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'
So I've tried prefixing the run command with winpty, and it executes the command but doesn't show me the interactive shell. When I type something, I cant see any of the commands that I'm typing into the terminal. I have to then type "reset" and then it sets the terminal back to normal. So I guess the winpty command isn't working
Questions:
Is there something wrong with the "winpty docker run -it dt_test" command and why doesn't it work?
How can I fix this issue to make my file run interactively?
FYI: When I run the docker file non interactively it seems to work fine. shows "Test" in the terminal according to the Dockerfile.
Looks to be the same as the input device is not a TTY.
Try without the -t:
docker run -i dt_test
And to run it with a different entrypoint (like bash):
docker run -i --entrypoint bash dt_test

Error when trying to create container with mounted volume

I'm trying to mount a volume on a container so that I can access files on the server I'm running the container. Using the command
docker run -i -t 188b2a20dfbf -v /home/user/shared_files:/data ubuntu /bin/bash
results in the error
docker: Error response from daemon: OCI runtime create failed:
container_linux.go:296: starting container process caused "exec: \"-v\":
executable file not found in $PATH": unknown.
I'm not sure what to do here. Basically, I need to be able to access a script and some data files from the host server.
The docker command line is order sensitive. After the image name, everything passed is a command that runs inside the container. For docker, the first thing that doesn't match an expected argument after the run command is assumed to be the image name:
docker run -i -t 188b2a20dfbf -v /home/user/shared_files:/data ubuntu /bin/bash
That tries to run a -v command inside your image 188b2a20dfbf because -t takes no value.
docker run -i -t -v /home/user/shared_files:/data 188b2a20dfbf /bin/bash
That would run bash in that same image 188b2a20dfbf.
If you wanted to run your command inside ubuntu instead (it's not clear from your example which you were trying to do), then remove the 188b2a20dfbf image name from the command:
docker run -i -t -v /home/user/shared_files:/data ubuntu /bin/bash
Apparently, on line 296 on your .go script you is referring to something that can't be found. Check your environment variables to see if they contain the path to that file, if the file is included in the volume at all, etc.
188b2a20dfbf passed to -t is not right. -t is used to get a pseudo-TTY terminal for the container:
$ docker run --help
...
-t, --tty Allocate a pseudo-TTY
Run docker run -i -t -v /home/user/shared_files:/data ubuntu /bin/bash. It works for me:
$ echo "test123" > shared_files
$ docker run -i -t -v $(pwd)/shared_files:/data ubuntu /bin/bash
root#4b426995e373:/# cat /data
test123

How to pass command line arguments to a docker image

I run tests inside docker image and I need to pass custom arguments
all the time.
When I put arguments after image name docker thinks that argument is image name.
docker run -t -i image-name -s test.py
docker run -t -i image-name -- -s test.py
Error:
Failed no image test_arena2.py
Docker version 1.11.2, build b9f10c9
You can build your Dockerfile with a combination of ENTRYPOINT and CMD instructions, which will let you run containers with or without arguments, e.g:
FROM ubuntu
ENTRYPOINT ["/bin/echo"]
CMD ["hello"]
That says the entrypoint is the echo command, and the default argument is hello. Run a container with no arguments:
> docker run temp
hello
Run with arguments and they all get passed to the entrypoint command:
> docker run temp -s stackoverflow
-s stackoverflow
docker run -i is good to be the begin of your command line then set of arguments for the run command only then at the very last -t image with image name provided
Image name should always be at the end of docker run command i.e. as last parameter to the command. Are you fine with passing the values as environment variable using below command
docker run -e "ENV_VAR_NAME=VALUE" -it image_name

docker run [9] System error: exec format error

I created Dockerfile to build my image called aii.
FROM docker.io/centos:latest
#Set parameters
ENV BinDir /usr/local/bin
ENV RunFile start-aii.sh
ADD ${RunFile} ${BinDir}
#Some other stuff
...
CMD ${RunFile}
When I run the image with the following command:
docker run -it -v <some-volume-mapping> aii
it's works great (default operation of running CMD command of start-aii.sh).
Now, if I try to override this default behavior and to run the image with the same script implicitly (and add another arg) I'm getting the following error:
docker run -it -v <some-volume-mapping> aii start-aii.sh kafka
exec format error
docker: Error response from daemon: Cannot start container b3f4f3bde04d862eb8bc619ea55b7061ce78ace8f1984a12f6ec681877d7d926: [9] System error: exec format error.
I also tried: only script (without argument)
docker run -it -v <some-volume-mapping> aii start-aii.sh
and full path to script
docker run -it -v <some-volume-mapping> aii /usr/local/bin/start-aii.sh
but the same error appear.
Another info:
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2488a4dd7014 aii "start-aii.sh kafka" 3 seconds ago Created tiny_payne
Any suggestions?
Thanks
Had the same issue, fixed it by adding #!/bin/sh at the top of the file instead of having other comments.
Try to start bash before using your script, and use the --rm flag in order to destroy the instance once the job is ended, like that :
docker run -it --rm -v <some-volume-mapping> aii /bin/bash /usr/local/bin/start-aii.sh
If you created the file start-aii.sh in the Windows editor. After that, this file was added to the docker image. You should check this file in a Linux editor, e.g. nano. In my case there were non-printable characters at the beginning of the file. I removed them and my script ran successfully.

Resources