Updated mount method, and container user management.

This commit is contained in:
2025-12-12 12:36:43 +01:00
parent a481704293
commit f054228de9
2 changed files with 12 additions and 8 deletions

View File

@@ -1,5 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Set default values
ACCOUNT_NAME="$(id -un)"
USER_NAME="ubuntu"
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case $1 in case $1 in
--account|-a) --account|-a)
@@ -7,7 +11,7 @@ while [ $# -gt 0 ]; do
shift 2 shift 2
;; ;;
--user|-u) --user|-u)
USERNAME="$2" USER_NAME="$2"
shift 2 shift 2
;; ;;
*) *)
@@ -19,10 +23,8 @@ done
IMAGE_NAME="skoszewski/azure-cli:latest" IMAGE_NAME="skoszewski/azure-cli:latest"
# Normalize account name for use in volume name # Normalize account name for use in volume name
ACCOUNT_NAME="${ACCOUNT_NAME:-$(id -un)}"
ACCOUNT_NAME="${ACCOUNT_NAME/@/_at_}" ACCOUNT_NAME="${ACCOUNT_NAME/@/_at_}"
ACCOUNT_NAME="${ACCOUNT_NAME//[-.]/_}" ACCOUNT_NAME="${ACCOUNT_NAME//[-.]/_}"
USERNAME="${USERNAME:-ubuntu}"
# Find container runtime # Find container runtime
if command -v podman &> /dev/null; then if command -v podman &> /dev/null; then
@@ -51,11 +53,13 @@ if ! $CMD volume inspect "account_$ACCOUNT_NAME" &> /dev/null; then
fi fi
# Run the container # Run the container
$CMD run --rm -it \ $CMD run \
-v "account_$ACCOUNT_NAME":/home/${USERNAME} \ --rm \
-v $(pwd):/workdir \ -it \
--mount type=volume,source="account_$ACCOUNT_NAME",target=/home/${USER_NAME} \
--mount type=bind,source=$(pwd),target=/workdir \
--name "azure-cli" \ --name "azure-cli" \
$HOSTNAME_ARG \ $HOSTNAME_ARG \
--workdir /workdir \ --workdir /workdir \
"$@" \ "$@" \
$IMAGE_NAME $IMAGE_NAME --user "$USER_NAME"

View File

@@ -20,7 +20,7 @@ done
# Check if the user exists # Check if the user exists
if ! id -u "$SU_USER" >/dev/null 2>&1; then if ! id -u "$SU_USER" >/dev/null 2>&1; then
useradd -m "$SU_USER" useradd -m -s /usr/bin/bash "$SU_USER"
fi fi
# Check if the home directory exists # Check if the home directory exists