'How to create a sh file to change directory and perform operations
I'm trying to connect to a Linux VM using a sh file running in my pipelines in order to create a small CI/CD solution. My idea is to login to the VM and perform a Docker compose down/up operation.
My VM is an Ubuntu 18
This is the code inside the bash file.
sshpass -p mypassword ssh -tt -o StrictHostKeyChecking=no user@vmip
cd ~ /folder/subfolder
docker-compose down
docker-compose up
I'm trying to run it locally and I get this error:
nodename nor servname provided, or not known : No such file or directoryfolder/subfolder No such command: down
Any workaround with this?
Thanks in advance!
Solution 1:[1]
I agree with Cyrus in your comments. Make sure docker-compose is installed on your VM. Additionally I would suggest you try something along the lines of the following for safety and some feedback for your own sanity.
if ! [ -x "$(command -v docker-compose)" ]; then
echo 'Error: docker-compose is not installed.' >&2
exit 1
fi
The above will ensure you have docker-compose installed before continuing.
Additionally I would suggest doing something along the lines of this to get you feedback and remember the -d for docker-compose up.
docker-compose down
echo
docker-compose up -d
echo
If you need new instances of your docker containers also don't forget to build them, otherwise you just keep reloading previously built containers, and that might become an issue depending on what you place in them.
docker-compose build
echo
Hope this helps.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kevin Smith |
