Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker /bin/sh: COPY: command not found

I tried to run this below command :

RUN if [ "$someargs" = "AAA" ]; then COPY from/ /usr/local/; fi

I got this error: This command returned a non-zero code: 127

like image 217
emoleumassi Avatar asked Feb 11 '26 08:02

emoleumassi


2 Answers

You can't do, inside a

RUN

a Dockerfile

COPY

You need to find another way, you may have a script that creates different Dockerfile based on your test.

like image 112
user2915097 Avatar answered Feb 12 '26 22:02

user2915097


As the error states, COPY is not a shell command, it's a docker instruction which is supposed start with a newline.

Syntax -
INSTRUCTION arguments

  1. You can use cp command in Dockerfile. However, you need to COPY the complete directory structure in your image to perform a cp operation. I haven't yet tried this yet but logically it should work.

  2. You can apply the shell logic at your host & use docker cp to actually copy contents from/to host to/from container.

Ref - https://docs.docker.com/engine/reference/builder/

like image 21
vivekyad4v Avatar answered Feb 13 '26 00:02

vivekyad4v



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!