Variables with docker

I’m trying to do a script which copies a file into a docker, and I wanted to use a variable for the command “docker exec -i [name_docker]” (Well, my boss want like it).
The problem comes when the variable isn’t making it’s job.

It keeps saying that there’s no variable

[email protected]:/home/user# bash -x test
+ set -e
++ docker exec -i dockerName
"docker exec" requires at least 2 arguments.
See 'docker exec --help'.

Usage:  docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

Run a command in a running container
+ cmd=
+ mkdir -p /home/ubuntu/testie
++ docker exec -i dockerName stat -c %a /home/ubuntu/testie/test
stat: cannot stat '/home/ubuntu/testie/test': No such file or directory
+ filepermissions=

That’s the error it gives me

#!/bin/bash
set -e

cmd=$(docker exec -i dockerName) mkdir -p /home/ubuntu/testie
filepermissions=$(docker exec -i dockerName -c '%a' /home/ubuntu/testie/test)
sudo docker cp /home/user/test dockerName:/home/ubuntu/testie
if [ $filepermissions == 777 ]; then
   echo "Free"
else
   echo "Restrictive. Gonna give it freedom"
   $commandDocker chmod 777 /home/ubuntu/testie/test
fi

I was expecting to get rid of that script easily, but it seems like I’ll carry it forever.

Source: StackOverflow