From ad55ba6eb2c0d30221bfd446bb8109b9650925de Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Mon, 12 Feb 2024 16:05:38 -0500 Subject: [PATCH] Handle DOCKER_HOST environment for podman-docker package Rootless users should be defaulted to point DOCKER_HOST at $XDG_RUNTIME_DIR/podman/podman.sock When podman-docker package is installed. [NO NEW TESTS NEEDED] Signed-off-by: Daniel J Walsh --- Makefile | 5 ++++- docker.in => docker/docker.in | 0 docker/podman-docker.csh | 10 ++++++++++ docker/podman-docker.sh | 11 +++++++++++ rpm/podman.spec | 3 ++- 5 files changed, 27 insertions(+), 2 deletions(-) rename docker.in => docker/docker.in (100%) create mode 100644 docker/podman-docker.csh create mode 100644 docker/podman-docker.sh diff --git a/Makefile b/Makefile index af79fdebe1..7645c9d006 100644 --- a/Makefile +++ b/Makefile @@ -875,10 +875,13 @@ install.completions: install.docker: install ${SELINUXOPT} -d -m 755 $(DESTDIR)$(BINDIR) $(eval INTERPOLATED_DOCKER_SCRIPT := $(shell mktemp)) - env BINDIR=${BINDIR} ETCDIR=${ETCDIR} envsubst < docker.in > ${INTERPOLATED_DOCKER_SCRIPT} + env BINDIR=${BINDIR} ETCDIR=${ETCDIR} envsubst < docker/docker.in > ${INTERPOLATED_DOCKER_SCRIPT} install ${SELINUXOPT} -m 755 ${INTERPOLATED_DOCKER_SCRIPT} $(DESTDIR)$(BINDIR)/docker rm ${INTERPOLATED_DOCKER_SCRIPT} install ${SELINUXOPT} -m 755 -d $(DESTDIR)${SYSTEMDDIR} $(DESTDIR)${USERSYSTEMDDIR} $(DESTDIR)${TMPFILESDIR} $(DESTDIR)${USERTMPFILESDIR} + install ${SELINUXOPT} -d -m 755 $(DESTDIR)${ETCDIR}/profile.d + install ${SELINUXOPT} -m 644 docker/podman-docker.sh $(DESTDIR)${ETCDIR}/profile.d/podman-docker.sh + install ${SELINUXOPT} -m 644 docker/podman-docker.csh $(DESTDIR)${ETCDIR}/profile.d/podman-docker.csh install ${SELINUXOPT} -m 644 contrib/systemd/system/podman-docker.conf -t $(DESTDIR)${TMPFILESDIR} install ${SELINUXOPT} -m 644 contrib/systemd/system/podman-docker.conf -t $(DESTDIR)${USERTMPFILESDIR} diff --git a/docker.in b/docker/docker.in similarity index 100% rename from docker.in rename to docker/docker.in diff --git a/docker/podman-docker.csh b/docker/podman-docker.csh new file mode 100644 index 0000000000..fd82a6e229 --- /dev/null +++ b/docker/podman-docker.csh @@ -0,0 +1,10 @@ +# DOCKER_HOST initialization + +if ($?DOCKER_HOST) exit +if ( "$euid" == 0 ) then + setenv DOCKER_HOST unix:///run/podman/podman.sock +else + if ($?XDG_RUNTIME_DIR) then + setenv DOCKER_HOST unix://$XDG_RUNTIME_DIR/podman/podman.sock + endif +endif diff --git a/docker/podman-docker.sh b/docker/podman-docker.sh new file mode 100644 index 0000000000..cd07e361e0 --- /dev/null +++ b/docker/podman-docker.sh @@ -0,0 +1,11 @@ +# DOCKER_HOST initialization + +if [ -z "$DOCKER_HOST" ]; then + if [ $(id -u) -eq 0 ]; then + export DOCKER_HOST=unix:///run/podman/podman.sock + else + if [ -n "$XDG_RUNTIME_DIR" ]; then + export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/podman/podman.sock + fi + fi +fi diff --git a/rpm/podman.spec b/rpm/podman.spec index cf073d9d18..62ca4dce9f 100644 --- a/rpm/podman.spec +++ b/rpm/podman.spec @@ -248,7 +248,7 @@ LDFLAGS='' %install install -dp %{buildroot}%{_unitdir} -PODMAN_VERSION=%{version} %{__make} PREFIX=%{buildroot}%{_prefix} ETCDIR=%{_sysconfdir} \ +PODMAN_VERSION=%{version} %{__make} DESTDIR=%{buildroot} PREFIX=%{_prefix} ETCDIR=%{_sysconfdir} \ install.bin \ install.man \ install.systemd \ @@ -300,6 +300,7 @@ cp -pav test/system %{buildroot}/%{_datadir}/%{name}/test/ %files docker %{_bindir}/docker %{_mandir}/man1/docker*.1* +%{_sysconfdir}/profile.d/%{name}-docker.* %{_tmpfilesdir}/%{name}-docker.conf %{_user_tmpfilesdir}/%{name}-docker.conf