Hi I have some problems with my LXC containers. If I run .sh script one, it does not create file in container, but the path exists. Sometimes, when I execute script several times, its working, i don`t know why.
Result: mkstemp: No such file or directory touch: cannot touch '/root/.ssh/config': No such file or directory /bin/sh: 13: cannot create /root/.ssh/config: Directory nonexistent
My script:
# Lets define some variables.
export CONTAINER="cv-app-backend-5"
export SSH_SRC_PATH="./ssh"
export SSH_DST_PATH="/root/"
export SSH_CONFIG_PATH="/root/.ssh/config"
export GIT_HOST="host"
export GIT_URI="git@git.git"
export APP_PATH="/root/app"
export SSH_PATH="/root/ssh/id_rsa"
export DB_USER="postgres"
export DB_PASSWORD="postgres"
#
# Nothing below this point should need to be modified.
#
# Create a default Debian container.
lxc launch 'images:debian/9' ${CONTAINER}
lxc config device add ${CONTAINER} http proxy \
listen=tcp:0.0.0.0:80 connect=tcp:127.0.0.1:80
lxc config device add ${CONTAINER} https proxy \
listen=tcp:0.0.0.0:443 connect=tcp:127.0.0.1:443
lxc config device add ${CONTAINER} http proxy \
listen=tcp:0.0.0.0:8080 connect=tcp:127.0.0.1:8080
lxc file push -r ${SSH_SRC_PATH} ${CONTAINER}${SSH_DST_PATH}
# Run a script in the container
cat <<EOF | lxc exec ${CONTAINER} -- /bin/sh
echo "In container, phase 1"
apt-get update
apt-get -y install sudo git
# Clone project repository
pwd
ls -la
rm -rf ${APP_PATH}
ssh-keygen -R ${GIT_HOST}
touch ${SSH_CONFIG_PATH}
echo "Host ${GIT_HOST}\n\tStrictHostKeyChecking no\n" >> ${SSH_CONFIG_PATH}
ssh-agent /bin/sh -c "ssh-add ${SSH_PATH}; git clone ${GIT_URI} ${APP_PATH}"
cd ${APP_PATH}
#In repository
git checkout develop
ssh-agent /bin/sh -c "ssh-add ${SSH_PATH}; git pull"
#git reset --hard
EOF