Showing posts with label containers. Show all posts
Showing posts with label containers. Show all posts

2018-07-17

Run docker container with access to the current working directory

Containers are an amazing technology and Docker makes it fast and easy to get one up and running, so you can make your local system look and behave like it were a different OS/distro/version. This can be extremely useful for testing how code behaves in different environments.

Sometimes, though, one does not have time to write a Dockerfile. For ad-hoc testing one sometimes would like to just get a bash prompt in a container. This can be done like so:

$ docker run -i -t opensuse bash

But this has the disadvantage (or advantage, depending on point of view) that the local filesystem is inaccessible. Docker gives the container a completely fresh filesystem to work in. What if we just want to give the container read/write access to the current working directory?

The magic incantation for that is:

docker run -v $(pwd):$(pwd) -w $(pwd) -i -t opensuse bash

Since that's unfit for storage in failing human memory, I'll put it here :-)

2017-03-04

Start a pristine, minimal SUSE system in an LXC container (no Docker)

Going through some old emails I stumbled upon some instructions from Thorsten Behrens on bringing up a clean, minimal SUSE environment in an LXC container using libvirt-lxc. Obviously that could be useful for testing things. I tried it on the laptop and tweaked it for Leap 42.2:

sudo zypper in lxc libvirt virt-install
sudo systemctl start libvirtd.service
mkdir libvirt
INSTALL_ROOT=/home/smithfarm/libvirt  # must be full path
sudo zypper \
    --root $INSTALL_ROOT \
    addrepo \
    http://download.opensuse.org/distribution/leap/42.2/repo/oss/ \
    repo-oss
sudo zypper \
    --non-interactive \
    --gpg-auto-import-keys \
    --root $INSTALL_ROOT \
    install \
    --auto-agree-with-licenses \
    aaa_base rpm zypper wget vim   # downloads and installs a bunch of stuff
sudo virsh net-start default       # does not happen automatically
sudo virt-install \
     --connect lxc:/// \
     --os-variant opensuse42.2 \
     --name opensuse42.2 \
     --ram 1024 \
     --filesystem $INSTALL_ROOT,/

This works and gets me to a login prompt, but I don't know the root password.

Break out of the container with "CTRL-]". Re-enter with:

sudo virsh --connect lxc:/// console opensuse42.2

Change the root password (or execute an arbitrary command as "root"):

sudo virsh -c lxc:/// lxc-enter-namespace opensuse42.2 --noseclabel /usr/bin/passwd