From 441bcc24bfc8d1a168720f0c53c065e0e03e3f80 Mon Sep 17 00:00:00 2001 From: pgillich Date: Tue, 5 Jan 2021 11:35:20 +0100 Subject: [PATCH] Improving Docker based Installation (#1194) To be able to use 'vagrant ssh' from within the docker container, it is necessary to run within the host network context. Include a helper alias suggestion and a note about a current issue in passing arguments to vagrant options which impacts the 'vagrant ssh -c ...' syntax with an alternative. --- Dockerfile | 2 ++ README.md | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/Dockerfile b/Dockerfile index 452fa31..0e5ca2d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -66,6 +66,8 @@ RUN for dir in boxes data tmp; \ FROM base as final +ENV VAGRANT_DEFAULT_PROVIDER=libvirt + COPY --from=build /vagrant /vagrant COPY entrypoint.sh /usr/local/bin/ diff --git a/README.md b/README.md index f242e3c..ea8ff6a 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,12 @@ To get the image: docker pull vagrantlibvirt/vagrant-libvirt:latest ``` +Preparing the docker run, only once: + +```bash +mkdir -p ~/.vagrant.d/{boxes,data,tmp} +``` + Running the image: ```bash docker run -it --rm \ @@ -119,10 +125,35 @@ docker run -it --rm \ -v ~/.vagrant.d:/.vagrant.d \ -v $(pwd):$(pwd) \ -w $(pwd) \ + --network host \ vagrantlibvirt/vagrant-libvirt:latest \ vagrant status ``` +It's possible to define an alias in `~/.bashrc`, for example: +```bash +alias vagrant=' + mkdir -p ~/.vagrant.d/{boxes,data,tmp}; \ + docker run -it --rm \ + -e LIBVIRT_DEFAULT_URI \ + -v /var/run/libvirt/:/var/run/libvirt/ \ + -v ~/.vagrant.d:/.vagrant.d \ + -v $(pwd):$(pwd) \ + -w $(pwd) \ + --network host \ + vagrantlibvirt/vagrant-libvirt:latest \ + vagrant' +``` + +Known issue of Docker based Installation: SSH command option cannot be used, so below command: +```bash +vagrant ssh master -c 'ls -la' +``` +should be call below way: +```bash +vagrant ssh master -- 'ls -la' +``` + Note that if you are connecting to a remote system libvirt, you may omit the `-v /var/run/libvirt/:/var/run/libvirt/` mount bind. Some distributions patch the local vagrant environment to ensure vagrant-libvirt uses `qemu:///session`, which means you