Using the CLI with Docker
December 22, 2023 ยท View on GitHub
The CLI can be used in Docker without any problem.
Basic usage
In order to use it you must mount the scaleway configuration file:
docker run -it --rm -v $HOME/.config/scw:/root/.config/scw scaleway/cli:v2.26.0
If you want to use scw instead of docker run you can add the following in your ~/.bashrc:
scw() {
docker run -it --rm -v $HOME/.config/scw:/root/.config/scw scaleway/cli:v2.26.0 "$@"
}
export -f scw
Or if you use ZSH, add the following in your ~/.zshrc:
scw() {
docker run -it --rm -v $HOME/.config/scw:/root/.config/scw scaleway/cli:v2.26.0 $@
}
Use your ssh-key
In order to use your ssh-key you must mount your .ssh folder
docker run -it --rm -v $HOME/.config/scw:/root/.config/scw -v $HOME/.ssh:/root/.ssh scaleway/cli:v2.26.0 $@
You can then ensure that your ssh key is present in your Scaleway account
scw iam ssh-key init
Autocompletion
You can still use autocompletion while running the CLI in Docker, you just need to modify script generated by the CLI.
For instance, scw autocomplete script shell=bash will return:
_scw() {
_get_comp_words_by_ref -n = cword words
output=$(scw autocomplete complete bash -- "$COMP_LINE" "$cword" "${words[@]}")
COMPREPLY=($output)
# apply compopt option and ignore failure for older bash versions
[[ $COMPREPLY == *= ]] && compopt -o nospace 2> /dev/null || true
return
}
complete -F _scw scw
And in your ~/.bashrc you can add:
scw() {
docker run -it --rm -v $HOME/.config/scw:/root/.config/scw scaleway/cli:v2.26.0 "$@"
}
export -f scw
_scw() {
_get_comp_words_by_ref -n = cword words
output=$(docker run -i --rm -v $HOME/.config/scw:/root/.config/scw scaleway/cli:v2.26.0 autocomplete complete bash -- "$COMP_LINE" "$cword" "${words[@]}")
COMPREPLY=($output)
# apply compopt option and ignore failure for older bash versions
[[ $COMPREPLY == *= ]] && compopt -o nospace 2> /dev/null || true
return
}
complete -F _scw scw
The trick is to remove the -t when using docker inside the completion function.
Using the CLI with Podman
If running with Podman and SELinux in enforcing mode, one must use the :Z option when mounting the configuration file.
For instance:
podman run -it --rm -v $HOME/.config/scw:/root/.config/scw:Z scaleway/cli:v2.26.0