0

I tried with #!/usr/bin/bash and #!/usr/bin/env/sh and #!/usr/bin/env/ bash

docker run -t -i image-id /bin/sh is what i use and use ls and i see that the file is there

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                       PORTS               NAMES
9c970708c1a3        bd24c6bef682        "/bin/sh -c 'sh benc…"   7 minutes ago       Exited (127) 7 minutes ago                       amazing_lovelace

I am able to run both these commands individually and they work

echo "Getting the Container Name"
containerName=$(docker ps -l --format '{{.Names}}' 2>&1)


echo "Transfering the text file"
docker cp $containerName:/benchmark.txt /Users/xxxx/Devlocal/xxxxx/tests/logs/benchmark.txt

when put in a shell script and run i get: ERROR

benchmark.sh: line 13: docker: not found
The command '/bin/sh -c sh benchmark.sh' returned a non-zero code: 127

please help dockerfile

FROM gliderlabs/alpine:3.5
MAINTAINER LN

RUN apk add --update alpine-sdk openssl-dev
RUN apk add --no-cache git

RUN git clone https://github.com/giltene/wrk2.git && cd wrk2 && make
ADD ["benchmark.sh", "/benchmark.sh"]
RUN sh benchmark.sh
Purple_haze
  • 68
  • 1
  • 10
  • Looks like `docker`’s not on your `$PATH`. Could it be that it works in (interactive) Bash because you modify `$PATH` in, say, `.bashrc`? – Biffen Aug 16 '18 at 05:58
  • didnt mess with any .bashrc in local/host – Purple_haze Aug 16 '18 at 06:07
  • What does `which docker`, in the shell where it works, show? And if you add `echo "$PATH"` to the script, what’s the output? – Biffen Aug 16 '18 at 06:09
  • @Purple_haze There is something you should know. If you want to run a container in a container, it likes vm nest. So you should know if your container supports it. – Charles Xu Aug 16 '18 at 06:10
  • @Biffen in local `/usr/local/bin/docker` in the container it shows nothing – Purple_haze Aug 16 '18 at 06:13
  • adding my dockerfile too – Purple_haze Aug 16 '18 at 06:14
  • @Purple_haze With an empty `$PATH` you can’t run any commands (except for the shell’s built-in ones) with just `command`; you’ll have to use `/path/to/command`, e.g. `/usr/local/bin/docker run -t …`. – Biffen Aug 16 '18 at 06:27
  • have you tried `RUN benchmark.sh`? or better `RUN chmod +x /benchmark.sh && /benchmark.sh` – Mazel Tov Aug 16 '18 at 06:46

1 Answers1

1

The script that you call inside the container, executes docker commands. This can only work if you have docker installed in your container, which, by the looks of it, it is not.

If your only aim is to have access to the file /benchmarks.txt, you can mount it when you start your container:

docker run -d -v /Users/xxxx/Devlocal/xxxxx/tests/logs/benchmark.txt:/benchmark.txt ...

Note that you have to add RUN touch /benchmark.txt to your Dockerfile.

The reason for that is here

NZD
  • 1,780
  • 2
  • 20
  • 29