Skip to content
This repository was archived by the owner on Apr 16, 2024. It is now read-only.

Commit 31a410f

Browse files
committed
chore: make contribute/start_docker work on Fedora
The docker-podman wrapper created volume mounts are owned by the root user inside the container, and the doom user wouldn't have write access. Need to specify --user-ns=keep-id flag to map $UID from the host to $UID from the container without using subuids: that way user inside container can modify. SELinux is on by default on Fedora36, thus volume mounts need to specify the 'Z' flag to relabel the directory being mounted. podman needs '--userns=keep-id' for permissions of mounted volumes to work inside the container. However docker doesn't recognize that flag (and doesn't need it, since it is running as root). Detect which of `docker` or `podman` is installed, and if it is podman add the extra flag. We need to check for podman first, because 'docker' might just be a wrapper that calls podman. Signed-off-by: Edwin Török <edwin@etorok.net>
1 parent ff1ccbd commit 31a410f

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

tools/start_docker.sh

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
#!/usr/bin/env bash
2-
3-
if ! docker info > /dev/null 2>&1; then
2+
DOCKER=$(command -v podman docker | head -n 1)
3+
if ! "${DOCKER}" info > /dev/null 2>&1; then
44
echo "This script uses docker, and it isn't running - please start docker and try again!"
55
exit 1
66
fi
77

8+
if [ $(basename "${DOCKER}") = "podman" ]; then
9+
DOCKER_RUN_FLAGS="--userns=keep-id"
10+
else
11+
DOCKER_RUN_FLAGS=
12+
fi
13+
814
############################################################
915
# Help #
1016
############################################################
@@ -40,6 +46,7 @@ while getopts "b:h" option; do
4046
exit;;
4147
esac
4248
done
49+
shift $((OPTIND-1))
4350

4451
cd "$SCRIPT_DIR" || exit
4552

@@ -87,30 +94,30 @@ echo ""
8794

8895
echo "2. Setting up docker environment"
8996
# Ensure docker image exists
90-
if [[ ! "$(docker images -q doom-nvim-contrib)" ]]; then
97+
if [[ ! "$("${DOCKER}" images -q doom-nvim-contrib)" ]]; then
9198
echo " - Docker image does not exist. Building docker image..."
92-
docker build -t doom-nvim-contrib .
99+
"${DOCKER}" build -t doom-nvim-contrib .
93100
fi
94101

95-
if [ "$(docker ps -aq -f status=exited -f name=doom-nvim-contrib-container)" ]; then
102+
if [ "$("${DOCKER}" ps -aq -f status=exited -f name=doom-nvim-contrib-container)" ]; then
96103
echo " - Cleaning up old container..."
97104
# cleanup
98-
docker rm doom-nvim-contrib-container >> /dev/null
105+
"${DOCKER}" rm doom-nvim-contrib-container >> /dev/null
99106
fi
100107

101108
# Create docker container if haven't already
102109
echo " - Success! Running docker container doom-nvim-contrib-container..."
103110
mkdir -p "${SCRIPT_DIR}/local-share-nvim" "${SCRIPT_DIR}/workspace"
104111
echo ""
105-
docker run \
112+
${DOCKER} run \
113+
"${DOCKER_RUN_FLAGS}" \
106114
-it \
107115
-e UID="1000" \
108116
-e GID="1000" \
109-
-v "$SCRIPT_DIR"/doom-nvim-contrib:/home/doom/.config/nvim \
110-
-v "$SCRIPT_DIR"/local-share-nvim:/home/doom/.local/share/nvim \
111-
-v "$SCRIPT_DIR"/workspace:/home/doom/workspace \
117+
-v "$SCRIPT_DIR"/doom-nvim-contrib:/home/doom/.config/nvim:Z \
118+
-v "$SCRIPT_DIR"/local-share-nvim:/home/doom/.local/share/nvim:Z \
119+
-v "$SCRIPT_DIR"/workspace:/home/doom/workspace:Z \
112120
--name doom-nvim-contrib-container \
113121
--user doom \
122+
"$@" \
114123
doom-nvim-contrib
115-
116-

0 commit comments

Comments
 (0)