Reputation: 1075
I have a script on the docker host that i want to run and create symbolic links inside its containers. However, i cannot seem to get the symbolic link created when i run my script below:
#!/bin/bash
declare -A containers
while IFS== read -r key value; do
containers[$key]=${value}
S=$(sudo docker exec -t $key ln -s /srv/my.cnf /etc/mysql/my.cnf);
done < "/opt/containers.txt"
The weird thing is that when i run the command outside the script directly in the terminal, it actually works. E.g.,
sudo docker exec -t db-test-1 ln -s /srv/my.cnf /etc/mysql/my.cnf
So not sure why it won't run in the script. Any suggestions?
Upvotes: 1
Views: 2443
Reputation: 1324937
For testing, you can see if isolating the command (here ln) in its own shel helps:
S=$(sudo docker exec -t $key /bin/sh -c "ln -s /srv/my.cnf /etc/mysql/my.cnf");
Upvotes: 1