docker-compose update container PATH - docker

I want to use docker-compose yml file to update the container's PATH.
environment:
- PATH="$PATH":/my/new/path
But when I start the container, it says
oci runtime error: exec failed: container_linux.go:265: starting container process caused "exec: \"bash\": executable file not found in $PATH"
Is it possible to update the container's PATH from docker-compose yml file?
Thanks.

What you are doing is updating the PATH, however the error is resulting from the fact that $PATH is being expanded to the env variable's value that is on the host.
What you can do is figure the PATH value that is inside the container by default and appending to that value:
Start the image without the variable:
docker-compose up
docker exec -it <container-name> bash
run echo $PATH and copy the value
replace the value in the compose file:
environment:
- PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/my/new/path

For me the error occurred when I was trying to execute my startup script command: bash startup.sh in docker-compose.
The problem was that my image build was made on alpine Linux which uses ash as shell instead of bash. Just double check that you are referring to correct shell interpreter. As well check that your sh scripts referring to correct unix shell e.g #!/bin/ash

Related

Docker: how do i format a CMD/EntryPoint to run my client and server in the same terminal

Concurrently allows me to run client and server simultaneously within the same terminal and the command for it is npm run dev from my server folder.
I am trying to avoid creating multiple Dockerfiles for client and server folder.
After building and image of my whole project, is it possible to use docker run [image] to call on CMD or ENTRYPOINT [npm run dev] to replicate the same behaviour as starting my application outside of docker? How would i format my DockerFile to go into server folder and runnpm run dev to load up client and server?
i gave my code a try and apparently the error i get back is docker: Error response from daemon: OCI runtime create failed: container_linux.go:370: starting container process caused: exec: "npm run dev": executable file not found in $PATH: unknown.
Your problem is that you are using the exec form of ENTRYPOINT/CMD:
Command line arguments to docker run will be appended after
all elements in an exec form ENTRYPOINT, and will override all
elements specified using CMD. This allows arguments to be passed to
the entry point, i.e., docker run -d will pass the -d argument
to the entry point. You can override the ENTRYPOINT instruction using
the docker run --entrypoint flag.
The shell form prevents any CMD or run command line arguments from
being used, but has the disadvantage that your ENTRYPOINT will be
started as a subcommand of /bin/sh -c, which does not pass signals.
This means that the executable will not be the container’s PID 1 - and
will not receive Unix signals - so your executable will not receive a
SIGTERM from docker stop .
To run num run dev on our container, you should use either
ENTRYPOINT ["npm", "run", "dev"] # using the exec form correctly
or
ENTRYPOINT npm run dev # using the shell form

Cannot run FreeBSD terminal in docker container

I am using a FreeBSD image from dockerhub. After pulling the image, I need to run a container with a terminal to test some commands inside the container.
I am trying this command:
sudo docker run --rm -it auchida/freebsd ./bin/bash
And I get the error:
docker: Error response from daemon: OCI runtime create failed:
container_linux.go:348: starting container process caused "exec:
\"./bin/bash\": stat ./bin/bash: no such file or directory": unknown
Could anyone help me ?
There is no bash binary embedded in the image, located at /bin/bash or everywhere else : you can check it by looking at base.txz contents.
You can use /bin/sh instead (the default shell, take a look at the Dockerfile) :
sudo docker run --rm -it auchida/freebsd /bin/sh
(/bin/sh is optional in the previous command, since it is the default CMD).
If you really want bash, you must install it.
Note also that you must be on a FreeBSD host to be able to run a container with this image.

msys2 and docker run specifying the command: looks for the command locally before running in docker

Within msys2, anytime I try to execute a docker run [image] [cmd] command such that I'm trying to run in the docker container overwrites the command specified in the Dockerfile, it looks for the command locally and fails if it doesn't exist.
For example, my organization has a docker image where the python executable is at /usr/src/venv/bin/python and python is not in $PATH. That is not where my local python is installed and when I try to run docker run myimage /usr/src/venv/bin/python test.py I get this error: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"C:/msys64/usr/src/venv/bin/python\": stat C:/msys64/usr/src/venv/bin/python: no such file or directory" This image is not a windows image and so it shouldn't be looking at C: at all so I must conclude it's looking for that command locally instead of within the container.
Note: The docker I'm running is Docker for windows added to my $PATH within msys2.
$ which docker
/c/Program Files/Docker/Docker/Resources/bin/docker.exe
One workaround I've used is to create a new Dockerfile that just has a line to say to use the image I want and another that is the command I want. Then I can run docker run some-image without specifying a command and it works.
Is there some way I can fix this problem within msys2 without the annoying workaround described above?
This is due to MinGW Posix Path Convertion.
I found two work arounds.
Use double-slash // to start the path, then MSYS won't translate the path:
docker run myimage //usr/src/venv/bin/python test.py
^^this
Another way is to suppress the path translation by setting MSYS_NO_PATHCONV=1 in Windows Git MSys or MSYS2_ARG_CONV_EXCL="*" in MSYS2.
Sources:
How to stop mingw and msys from mangling path names given at the command line?
https://github.com/git-for-windows/git/issues/577#issuecomment-166118846

OCI runtime exec failed: exec failed: (...) executable file not found in $PATH": unknown

I have dockerized an app which has ffmpeg installed in it via libav-tools. The app launches without problem, yet the problem occured when fluent-ffmpeg npm module tried to execute ffmpeg command, which was not found. When I wanted to check the version of the ffmpeg and the linux distro set up in the image, I used sudo docker exec -it c44f29d30753 "lsb_release -a" command, but it gave the following error: OCI runtime exec failed: exec failed: container_linux.go:296: starting container process caused "exec: \"lsb_release -a\": executable file not found in $PATH": unknown
Then I realized that it gives me the same error with all the commands that I try to run inside the image or the container.
OCI runtime exec failed: exec failed: container_linux.go:296: starting container process caused "exec: \"ffmpeg -a\": executable file not found in $PATH": unknown
This is my Dockerfile:
FROM ubuntu:xenial
FROM node
RUN apt-get -y update
RUN apt-get --yes install libav-tools
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app
RUN npm install
COPY . /usr/src/app
RUN npm run build
ENV NODE_ENV production
EXPOSE 8000
CMD ["npm", "run", "start:prod"]
I would kindly ask for your help. Thank you very much!
This happened to me on windows. See below for any of the commands that match your case.
NOTE
You will need to run the commands that match your case below using the correct shell in your container i.e. /bin/bash or /bin/sh. Using sh instead of bash or vice versa will also give you this error. So, confirm that you are using the right shell, or just try both shells and see the one that works.
For these examples, I will be using sh
On Windows CMD (not switching to bash):
docker exec -it <container-id> /bin/sh
On Windows CMD (after switching to bash):
docker exec -it <container-id> //bin//sh
or
winpty docker exec -it <container-id> //bin//sh
On Git Bash:
winpty docker exec -it <container-id> //bin//sh
For Windows users, the reason is documented in the ReleaseNotes file of Git and it is well explained here - Bash in Git for Windows: Weirdness... :
The cause is to do with trying to ensure that posix paths end up being
passed to the git utilities properly. For this reason, Git for Windows
includes a modified MSYS layer that affects command arguments.
Linux
docker exec -it <container-id> /bin/sh
docker exec -it <containerId> sh
I had this due to a simple ordering mistake on my end. I called
[WRONG] docker run <image> <arguments> <command>
When I should have used
docker run <arguments> <image> <command>
Same resolution on similar question: https://stackoverflow.com/a/50762266/6278
If #papigee does solution doesn't work, maybe you don't have the permissions.
I tried #papigee solution but does't work without sudo.
I did :
sudo docker exec -it <container id or name> /bin/sh
Get rid of your quotes around your command. When you quote it, docker tries to run the full string "lsb_release -a" as a command, which doesn't exist. Instead, you want to run the command lsb_release with an argument -a, and no quotes.
sudo docker exec -it c44f29d30753 lsb_release -a
Note, everything after the container name is the command and arguments to run inside the container, docker will not process any of that as options to the docker command.
For others with this error, the debugging steps I'd recommend:
Verify the order of your arguments. Everything after the container name/id is a command to run. So you don't want docker exec $cid -it /bin/sh because that will try to run the command -it in the $cid container. Instead you want docker exec -it $cid /bin/sh
Look at the command that is failing, everything in the quotes after the exec error (e.g. lsb_release -a in "exec: \"lsb_release -a\") is the binary trying to be run. Make sure that binary exists in your image. E.g. if you are using alpine or busybox, bash may not exist, but /bin/sh does. And that binary is the full string, e.g. you would be able to run something like ls "/usr/bin/lsb_release -a" and see a file with the space and -a in the filename.
If you're using Windows with Git bash and see a long path prefixed on that command trying to be run, that's Git bash trying to do some automatic conversions of /path/to/binary, you can disable that by doubling the first slash, e.g. //bin/sh.
If the command you're running is a script in the container, check the first line of that script, containing the #!/path/to/interpreter, make sure that interpreter exists in the image, at that path, and that the script is saved with linux linefeeds (lf, not cr+lf, you won't want the \r showing in the file when read in linux because that becomes part of the command it's looking to execute).
If you don't have a full path to the binary in the command you're running, check the value of $PATH in the image, and verify the binary exists within one of those directories. E.g. you can docker exec -it $cid /bin/sh and echo $PATH and type some_command to verify some_command is found in your path.
If your command is not an executable, but rather a shell builtin, you'll need to execute it with a shell instead of directly. That can be done with docker exec -it $cid /bin/sh -c "your_shell_builtin"
I solved this with this commands:
Run the container:
docker run -d <image-name>
List containers:
docker ps -a
Use the container ID:
docker exec -it <container-id> /bin/sh
I was running into this issue and it turned out that I needed to do this:
docker run ${image_name} bash -c "${command}"
You can use another shell to execute the same command:
Error I get when i execute:
[jenkins#localhost jenkins_data]$ docker exec -it mysqldb \bin\bash
OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: \"binsh\": executable file not found in $PATH": unknown
Solution:
When I execute it with below command, using bash shell it works:
[jenkins#localhost jenkins_data]$ docker exec -it mysqldb bash
root#<container-ID>:/#
What I did to solve was simply:
Run docker ps -a
Check for the command of the container (mine started with /bin/sh)
Run docker-compose exec < name_of_service > /bin/sh (if that is what started your command
This is for solving when using docker compose
I was running a container in a docker-compose.
entrypoint:
- ls
worked, but
entrypoint:
- ls tests
did not.
It's because the arguments have to be on separate lines.. 🤦‍♂
entrypoint:
- ls
- tests
This has happened to me. My issue was caused when I didn't mount Docker file system correctly, so I configured the Disk Image Location and re-bind File sharing mount, and this now worked correctly.
For reference, I use Docker Desktop in Windows.
In my case i saved the docker image and instead of load-ing it on the other machine i imported it which are very different and lead me to an error similar to this.
you have to run like below:
docker exec sh -c 'echo "$ENV_NAME"'
I had windows line endings in a shell script. change to LF dos2unix
If you got this error when using the docker run command, you may have made a simple syntax error.
Example
Incorrect:
docker run myimage -p 3838:3838
docker: Error response from daemon: failed to create shim: OCI runtime create
failed: container_linux.go:380: starting container process caused:
exec: "-p": executable file not found in $PATH: unknown.
ERRO[0000] error waiting for container: context canceled
Correct (options go before image name):
docker run -p 3838:3838 myimage

Docker --env-file - executable file not found in $PATH

I want to run my docker container with environment variables with the --env-file option, like mentioned in the docker doc: docker run command
I've tried creating a file named env.list in my home dir /home/jw/data with the following content:
SSL_CERTIFICATE_PATH=/opt/onlyoffice/Data/certs/onlyoffice.crt
SSL_KEY_PATH=/opt/onlyoffice/Data/certs/onlyoffice.key
SSL_DHPARAM_PATH=/opt/onlyoffice/Data/certs/dhparam.pem
After that I added the directory /home/jw/data/ to my $PATH environment variable:
PATH=$PATH:/home/jw/data/; export PATH
On the same shell I started the docker container like this:
sudo docker run -i -t -d --name onlyoffice-document-server onlyoffice/documentserver --env-file /home/jw/data/env.list debian env
I get the following error message:
Error response from daemon: Cannot start container 45ff897e0cfdc676f4f0bac98e027e2c567558a173a7f80c02ba6dc86482a176: [8] System error: exec: "--env-file": executable file not found in $PAT
I've also tried setting the $PATH under root and execute the mentioned run command, with the same error message.
Did I miss something?
onlyoffice/documentserver is at the wrong position.
Assuming that is the name of the container you want to start, it would have to be before env instead of debian, which is another image.
I think flag placement matters,
docker run --network="host" --env-file .env container_id

Resources