1 of 27

Everything As Code

Spring 2025

1

2 of 27

Outline

  1. Version Control Review
  2. Everything As Code: Discussion
  3. Introduction to Containerization with Docker
  4. Lab 4

2

3 of 27

Outline

  • Version Control Review
  • Everything As Code: Discussion
  • Introduction to Containerization with Docker
  • Lab 4

3

4 of 27

Version Control Review

Questions like these will definitely�be on the midterm exam

5 of 27

Syncing Across Different Repos

  • How do you download changes from a remote version of the repository to your local computer?
  • How do you upload changes from your computer to a remote repository?
  • What does the “origin” typically refer to?
    • How do you check the origin?
    • How do you set it?
    • How do you change it?

6 of 27

Branches

  • What is a branch?
  • How do you switch between branches?
  • How do you create a branch
  • How do you delete a branch?

7 of 27

Suppose you have a branch off of main called Feature-Branch, and suppose one commit has been made to main since you branched.

Redraw the history after a merge commit is used to reconcile the history. What branch should you be on to merge into main? What command would you use?

8 of 27

Suppose you have a branch off of main called Feature-Branch, and suppose one commit has been made to main since you branched.

Redraw the history after a rebase is used to reconcile the history. What branch should you be on to merge into main? What command would you use?

9 of 27

What is the difference between a fast forward merge and a regular merge?

Your answer here…

10 of 27

What are the steps to resolve a merge conflict during a rebase?

<<<<<<< HEAD

[Feature A Code]

=======

[Feature B Code]

>>>>>>> 1a0ffaa (Add feature b)

  1. git rebase feature-branch (main is the current branch)
  2. Manually resolve the conflicts in main.py
  3. Stage the edited file:�git add main.py
  4. Continue rebasing:�git rebase --continue

main.py

11 of 27

Outline

  • Version Control Review
  • Everything As Code: Discussion
  • Introduction to Containerization with Docker
  • Lab 4

11

12 of 27

Everything As Code

Also known as “Infrastructure as Code”

  • Discussion of the Seth Vargo Talk
  • What’s the big idea here?

13 of 27

History of Server Management

  • What were "servers" way back in the day?
  • What are "servers" now?
  • What kinds of challenges to current server administrators need to be able to navigate gracefully?

14 of 27

Virtualization and Containerization

Both are ways of isolating computational environments to run applications, but they work differently “under the hood”:

  • Virtualization – Abstracts the physical hardware to create multiple virtual machines (VMs). Each VM has its own operating system, which runs on top of a hypervisor (e.g., VMware, Hyper-V, or KVM).
    • Example: Running Windows and Linux on the same machine
  • Containerization – Containerization uses the operating system’s kernel features to run multiple isolated environments (containers) on the same OS. Instead of virtualizing the hardware, containers share the host OS kernel.
    • Example: Running multiple microservices on the same OS using Docker containers.

15 of 27

So much complexity – many services are virtualized all over the place. How do we manage it? Even if you’re not actually maintaining the hardware, you’re still on the hook for the software configuration / maintenance.

16 of 27

Codification of Management Rules

  • Code:
    • A formal, unambiguous way of describing a series of steps
    • Can be either imperative or declarative – what’s the difference?
  • Examples of imperative codification: shell / bash script
  • Examples of declarative codification:
    • Docker files (Containers)
    • package.json (Node.js)
    • requirements.txt (Python)
    • Poetry files (Python)
    • Terraform files (Infrastructure)

17 of 27

Allows you to version control all the things!

  • Product Code
  • Documentation (Markdown)
  • Product Configuration (Feature Flags)
  • Developer Environments (Vagrant, Docker)
  • Enterprise Infrastructure (Chef, Puppet)
  • Server Infrastructure (Docker, Terraform)

Allows you to formally inspect how things have evolved / changed; Allows you to consistently replicate / rebuild / maintain your infrastructure.

18 of 27

In the next few weeks…

  • We’ll be talking more about linting, testing, and continuous integration / deployment in the weeks ahead! Stay tuned!

19 of 27

Outline

  • Version Control Review
  • Everything As Code: Discussion
  • Introduction to Containerization with Docker
  • Lab 4

19

20 of 27

Introduction to Containerization with Docker

Enabled by Linux Kernel technologies:

  • chroot (short for “change root”) – changes the apparent root directory for a running process and its children. A process running inside of a chroot environment perceives the specified directory as the root (/) of the filesystem, isolating it from the rest of the system.
  • cgroups (short for control groups) – allow you to limit, isolate, and monitor the resource usage (such as CPU, memory, disk I/O, and network bandwidth) of a group of processes.

Both are fundamental technology used in modern container runtimes like Docker and Kubernetes to manage resources for containers.

21 of 27

Why is Docker a Big Deal?

  • Allows you to experiment with different version of operating systems, software, etc. without defiling your actual operating system.
    • If you mess something up, just delete the container and try again!
  • Allows you to run multiple servers on your laptop conveniently.
  • Has a declarative configuration language that makes it easy to create new server instances.
  • There’s a whole repository of pre-made Docker images and configuration files that you can utilize!

22 of 27

Docker Definitions

Image – a read-only template used to build containers.

  • Images are used to store and ship applications
  • Include everything needed to run an application: code, runtime, system tools, system libraries and settings.

Container – A runtime instance of a docker image.

  • A container will always run the same, regardless of the infrastructure.
  • Containers isolate software from its environment and ensure that it works uniformly

23 of 27

Docker Definitions (Cont’d)

Volume – provides the ability to connect specific filesystem paths of the container back to the host machine.

  • This is important for persisting state.
  • If a directory in the container is “mounted,” changes in that directory are also seen on the host machine.
  • If we mount that same directory across container restarts, we'd see the same files.
  • Think of a volume as a “bucket of persistent data” that can be accessed both within and outside of a container.

24 of 27

Docker Definitions (Cont’d)

Bind Mountsallow you to mount your source code into the container so that your container can “see” the changes right away.

  • You can use a tool like “nodemon” to watch for file changes and to restart any relevant services (so that code changes are immediately applied to your application).

25 of 27

A few other rules of thumb…

  1. In general, each container should do one thing and one thing only. For instance:
  2. One container to for the web service
  3. One container for the database service
  4. One container for the machine learning / recommendation system process…

  • Don’t be afraid to destroy and rebuild your containers – that’s why these tools exist – to minimize the pain associated with development environments

26 of 27

Today’s Activity

  1. Install Docker
  2. For WSL users:
    1. Ensure that Docker can interact with WSL
  3. Begin the Docker Tutorial. To do this:
    • Ensure that Docker is running
    • Open the command prompt
    • Run the following command: �docker run -dp 80:80 docker/getting-started
    • Open Then you can open http://localhost in your browser to complete the tutorial.

27 of 27

Today’s Activity

Open the command prompt and run the following command: �docker run -dp 80:80 docker/getting-started. Then you can open http://localhost in your browser to complete the tutorial.

  1. Getting Started
  2. Our Application
  3. Updating Our App
  4. Sharing Our App (Optional)
  5. Persisting our DB
  6. Using Bind Mounts
  7. Multi-Container Apps
  8. Using Docker Compose
  9. Image Building Best Practices (Optional)