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

Commit

Permalink
chore: make contribute/start_docker work on Fedora
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
edwintorok committed Aug 7, 2022
1 parent ff1ccbd commit 2ad89e4
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions tools/start_docker.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#!/usr/bin/env bash

if ! docker info > /dev/null 2>&1; then
DOCKER=$(command -v podman docker | head -n 1)
if ! "${DOCKER}" info > /dev/null 2>&1; then
echo "This script uses docker, and it isn't running - please start docker and try again!"
exit 1
fi

if [ $(basename "${DOCKER}") = "podman" ]; then
DOCKER_RUN_FLAGS="--userns=keep-id"
else
DOCKER_RUN_FLAGS=
fi

############################################################
# Help #
############################################################
Expand Down Expand Up @@ -40,6 +46,7 @@ while getopts "b:h" option; do
exit;;
esac
done
shift $((OPTIND-1))

cd "$SCRIPT_DIR" || exit

Expand Down Expand Up @@ -87,30 +94,30 @@ echo ""

echo "2. Setting up docker environment"
# Ensure docker image exists
if [[ ! "$(docker images -q doom-nvim-contrib)" ]]; then
if [[ ! "$("${DOCKER}" images -q doom-nvim-contrib)" ]]; then
echo " - Docker image does not exist. Building docker image..."
docker build -t doom-nvim-contrib .
"${DOCKER}" build -t doom-nvim-contrib .
fi

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

# Create docker container if haven't already
echo " - Success! Running docker container doom-nvim-contrib-container..."
mkdir -p "${SCRIPT_DIR}/local-share-nvim" "${SCRIPT_DIR}/workspace"
echo ""
docker run \
${DOCKER} run \
${DOCKER_RUN_FLAGS} \
-it \
-e UID="1000" \
-e GID="1000" \
-v "$SCRIPT_DIR"/doom-nvim-contrib:/home/doom/.config/nvim \
-v "$SCRIPT_DIR"/local-share-nvim:/home/doom/.local/share/nvim \
-v "$SCRIPT_DIR"/workspace:/home/doom/workspace \
-v "$SCRIPT_DIR"/doom-nvim-contrib:/home/doom/.config/nvim:Z \
-v "$SCRIPT_DIR"/local-share-nvim:/home/doom/.local/share/nvim:Z \
-v "$SCRIPT_DIR"/workspace:/home/doom/workspace:Z \
--name doom-nvim-contrib-container \
--user doom \
doom-nvim-contrib


doom-nvim-contrib \
"$@"

0 comments on commit 2ad89e4

Please sign in to comment.