Mounts

Week 0x8 I

Prof. Calvin

Crypto

Announcements

  • Welcome to variously CS 276/CS 540
    • Back to containers.
    • Week off from C
    • Two lectures with exercises
  • Action Items:
    • Basedterm ✔️
    • BigRSA due 31 Mar

Today

  • The file system
  • Linux and even… WINDOWS development????
    • Has science gone too far
  • Symbolic Linkages
  • Containers but good

Motivation

Motivation

Motivation

In brief

  • I am often on a Linux partition when a non-technical PM attempts to reach me through MS Suite
    • I can run MS Suite on Linux which, uh, defeats to purpose of being on Linux

In brief

  • I am often on a Windows partition when I get questions like:
    • Can I fix this compatibility issue with whitespace line termination?
    • Will this run on Win and *nix?
    • Can you take a quick md5sum of this file?
  • Often I just need to run a quick script or executable on files in a Windows file system using Linux syscalls.

Separate Problem

  1. vim mywork.c
  2. podman build -t tester . # COPY mywork.c
  3. podman run tester python3 tester.py
  4. I get negative one billion points
  5. vim mywork.c
  6. podman run tester python3 tester.py still gives negative on billion because the file systems are desynced.

Bind Mounts

When you use a bind mount, a file or directory on the host machine is mounted from the host into a container. By contrast, when you use a volume, a new directory is created within Docker’s storage directory on the host machine, and Docker manages that directory’s contents.

Let’s step through the process

  • I make a container image that I’m relatively happy with.
    • Save this in a containerfile
    • Build it and have it live under the local podman images container repository.
    • Or… push to GHCR? Hmmm?
      • Soon™️

Container image

  • I rarely use utilities other than these few.
Containerfile

Astyle

  • astyle might be new to you
  • It completely rules
  • It’s old, new one is Clang-Tidy
  • Requires LLVM back-end which is…
  • For the Rust class
  • Also coc usually via npm and (gags) neovim

Sample

Hightlight

  • vim octal.c
before
#include <stdio.h>
int main(){printf("%o\n",10);/* hm */return/* blah */ 0;}
  • astyle octal.c
astyle
#include <stdio.h>
int main() {
    printf("%o\n",10);/* hm */return/* blah */ 0;
}
  • Learn more astyle -h (I’ve never read it).

Style Guides

  • The people that taught me C wrote this
  • The iconic living legend Linux kernel hackers, who are never wrong, wrote this
  • I’m not up-to-date on Google C but Google C++ is here

Anyways

  • To my knowledge this is all I’ve used this term outside of one-offs for testing.
gcc \
vim \
python3 \
astyle
  • Though can probably manage gcc only after today.

Let’s step through the process

  • I make a container image that I’m relatively happy with.
    • vim Containerfile
    • podman build -t crypto .
  • Now, just spin up a transient container when I need anything.

Run options

  • Two competing idealogues
    • I am on docker documentation not podman
    • podman I think assumes you know what you are doing (I don’t)
  • Mount
  • Volume

Quote Docker

In general, --mount is preferred. The main difference is that the --mount flag is more explicit and supports all the available options.

  • Volume is basically being gradually depreciated.
  • Volumes are in general podman/docker managed and…
    • We don’t trust code other people wrote.
    • Or code we wrote.

Sample

Breakdown

Arg Meaning
podman container command
run start a container from some image
–mount let container see files that live outside container

Breakdown

Arg Meaning
type=bind the files will be the same in a host folder and container folder
src= This is the folder on the host
$PWD/.. This is the file above the current working directory

Try it

  • $PWD is a shell built-in like $?
  • Can use it in scripts.

Sample

  • Make the .. directory on host be visible to container.

Breakdown

Arg Meaning
target= This is the folder on the container
/mnt That is the mnt (mount) directory under root /
-d Start the container detached
  • I couldn’t get this to work attached (on Windows) but didn’t try very hard.
    • On Linux everything is easy (always)

Breakdown

Arg Meaning
-t What should the name (tag) be of Container image?
crypto The tag I used during podman build
/bin/bash The executable to run within the container

Sample

  1. Start a shell
  2. In a container of the image based on the Containerfile
  3. Where /mnt refers to files on the host machine

See it

More fun

  • I have gcc inside that container.
  • I can compile inside that container.
  • Let’s step through an example.
  • On my host, that is, not in container:
hi.c
#include <stdio.h>

int main() {
        printf("hi\n");
        return 0;
}

Compile

  • I can compile within the Container
    • Just use exec (run command)
    • With gcc
    • With /mnt files

Run it

  • Can run on the host device.
    • Well, making some pretty heavy assumptions.
    • This was ubuntu-to-ubuntu, after all
  • Can run in the container

Ubuntu on Windows

  • An astute learning will notice this means it no longer matters which OS your text editor runs under
  • And here, in this class, we all love MS Windows.

Windows Commands

  • Windows has two command lines.
    • Don’t blame me I voted for Free and Open Source Software (FOSS)
    • So does Windows, now (hence WSL)
  1. cmd.exe from DOS, which runs .bat files
  2. PowerShell, for .NET, which runs .ps1 files

Why two shells?

  • How does Windows work (pick one):
    • It doesn’t.
    • I don’t know.

Scripts

  • For reference, here is my .sh script to mount folders:
podman.sh
  • Here is how I run the same under the “Command” shell cmd.exe
windows.bat

One difference

  • podman commands are the same on all OSes
  • All commands within the container are the same, as the container is the same
  • The only difference is the src
    • On Windows:
      • Paths are backslash vs. forward slash delineated
      • %cd% not$PWD` gives the current directory.
      windows.bat

Windows Image

  • Presumably I can refer to wsl images from the Windows host, I didn’t try.

Launch Container

vim

  • I of course also have vim installed on Windows, but I don’t know when I did that or how.

Compile

Run

  • Windows Development: It’s easy.

It’s not

  • Windows opened a window asking me what to do when I tried to run this.

Exercise

  • Windows users:
    • Get this to run in PowerShell
  • Mac users:
    • Get this to run on Mac, the .sh should mostly work. Right?
  • Linux users:
    • Develop a “portable” binary that works across distributions.

Announcements

  • Welcome to variously CS 276/CS 540
    • Back to containers.
    • Week off from C
    • Two lectures with exercises
  • Action Items:
    • BigRSA due 31 Mar