0

For the following dockerfile

FROM ubuntu:20.04
COPY apache-cassandra-3.11.6-bin.tar.gz .
RUN tar -xzf apache-cassandra-3.11.6-bin.tar.gz 
RUN ls
RUN echo $PATH
RUN pwd
RUN export CASSANDRA_HOME = /apache-cassandra-3.11.6
RUN export PATH = $PATH:$CASSANDRA_HOME/bin
RUN echo $PATH
RUN ls
WORKDIR apache-cassandra-3.11.6/bin
RUN ls
CMD ["cassandra","-f"]

I am getting error

/bin/sh: 1: export: : bad variable name
The command '/bin/sh -c export CASSANDRA_HOME = /apache-cassandra-3.11.6' returned a non-zero code: 2

Why?

The full output is

C:\Users\manuc\Documents\manu\cassandra_image_test>docker build -f CassandraImageDockerFile.txt -t manucassandra .
Sending build context to Docker daemon  184.8MB
Step 1/13 : FROM ubuntu:20.04
 ---> 74435f89ab78
Step 2/13 : COPY apache-cassandra-3.11.6-bin.tar.gz .
 ---> Using cache
 ---> caa6b38eaee8
Step 3/13 : RUN tar -xzf apache-cassandra-3.11.6-bin.tar.gz
 ---> Using cache
 ---> f05803d3b504
Step 4/13 : RUN ls
 ---> Running in a4c1eba27e03
apache-cassandra-3.11.6
apache-cassandra-3.11.6-bin.tar.gz
bin
boot
dev
etc
home
lib
lib32
lib64
libx32
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
Removing intermediate container a4c1eba27e03
 ---> b0734ff6ee6d
Step 5/13 : RUN echo $PATH
 ---> Running in 0e001fd39c0b
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Removing intermediate container 0e001fd39c0b
 ---> dd41966e8b65
Step 6/13 : RUN pwd
 ---> Running in 7f5a3ff2952e
/
Removing intermediate container 7f5a3ff2952e
 ---> 614449c7e7b9
Step 7/13 : RUN export CASSANDRA_HOME = /apache-cassandra-3.11.6
 ---> Running in ba11d2594acd
/bin/sh: 1: export: : bad variable name
The command '/bin/sh -c export CASSANDRA_HOME = /apache-cassandra-3.11.6' returned a non-zero code: 2

C:\Users\manuc\Documents\manu\cassandra_image_test>
Manu Chadha
  • 15,555
  • 19
  • 91
  • 184
  • 1
    Syntax errors aside, `RUN export ...` is a no-op: any environment variables that get set this way will get lost at the end of the `RUN` instruction. You need the Dockerfile `ENV` directive to set persistent environment variables. See [docker ENV vs RUN export](https://stackoverflow.com/q/33379393/10008173) and [In a Dockerfile, How to update PATH environment variable?](https://stackoverflow.com/q/27093612/10008173). – David Maze Jun 29 '20 at 00:55

1 Answers1

1

It seems like a parsing error, /bin/sh: 1: export: : bad variable name. It didn't even try to export your variable. Have you tried simply removing the whitespaces and see if it works?

RUN export CASSANDRA_HOME=/apache-cassandra-3.11.6

RUN export PATH=$PATH:$CASSANDRA_HOME/bin

Pedro Rocha
  • 154
  • 6
  • Thanks. That solved the parse error but doesn't seem to have set the PATH as the 2nd PATH print doesn't show the cassandra bin directory – Manu Chadha Jun 28 '20 at 15:04