Professional Documents
Culture Documents
ziritrion / vm_containers.md
Last active last week
Star
vm_containers.md
Multipass
Tool to run Ubuntu VM's easily with command-line interface.
multipass list
Create and launch a new instance using the latest LTS release
Stop an instance
https://gist.github.com/ziritrion/1842c8a4c4851602a8733bba19ab6050 1/9
12/15/22, 12:09 PM Cheatsheet for various container and VM thingies · GitHub
multipass purge
Docker
Terminology
Container: environment that runs an applications that is not dependent on the OS.
Kind of like a lightweight VM. Containers are stateless; if you need to update the
components inside, create another container instead.
Image: template to create a container. Its components are defined by a Dockerfile .
Volume: storage area detached from the container for maintaining state.
Foreground/interactive vs background/detached: a detached container runs in the
background whereas an interactive container will usually have a terminal of some sort
for interacting with.
Commands
List your local images
docker images
https://gist.github.com/ziritrion/1842c8a4c4851602a8733bba19ab6050 2/9
12/15/22, 12:09 PM Cheatsheet for various container and VM thingies · GitHub
docker image rm
docker ps
Run a Docker image inside a container and map a port in the container to a port in the
host machine
# Install dependencies
RUN pip install -r requirements
https://gist.github.com/ziritrion/1842c8a4c4851602a8733bba19ab6050 3/9
12/15/22, 12:09 PM Cheatsheet for various container and VM thingies · GitHub
Docker will process each line as a layer. Some layers are cached, so in order to speed
up build time, first copy and run immutable objects and then take care of your
code/modules, as shown in this example.
Base images are useful because they save a lot of work and build time. Choose a lean
base image and avoid unnecessary packages.
Each container should only have one concern. Decouple applications into multiple
containers.
Create a slightly more complex Dockerfile with pipenv dependencies and specific
entrypoints.
# Specify entrypoint
ENTRYPOINT ["gunicorn", "--bind=0.0.0.0:9696", "predict:app"]
The COPY instruction has 2 forms, shown here. The second form (like for pipenv in this
example) must be used if any paths may contain whitespaces. The last param is always
https://gist.github.com/ziritrion/1842c8a4c4851602a8733bba19ab6050 4/9
12/15/22, 12:09 PM Cheatsheet for various container and VM thingies · GitHub
Docker compose
Example docker-compose.yaml file.
version: "3.9"
services:
model-server:
image: zoomcamp-10-model:v1
gateway:
image: zoomcamp-10-gateway:v2
environment:
- TF_SERVING_HOST=model-server:8500
ports:
- "9696:9696"
https://gist.github.com/ziritrion/1842c8a4c4851602a8733bba19ab6050 5/9
12/15/22, 12:09 PM Cheatsheet for various container and VM thingies · GitHub
docker-compose up
docker-compose up -d
docker-compose down
Kubernetes
Kind
Create local cluster
eksctl
Create a default cluster on EKS.
https://gist.github.com/ziritrion/1842c8a4c4851602a8733bba19ab6050 6/9
12/15/22, 12:09 PM Cheatsheet for various container and VM thingies · GitHub
Example eks-config.yaml
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: mlzoomcamp-eks
region: eu-west-1
nodeGroups:
- name: ng-m5-xlarge
instanceType: m5.xlarge
desiredCapacity: 1
metadata contains both the name of the cluster as well as the AWS region .
nodeGroups contains a list of node groups. In this example the list has a single entry.
desiredCapacity contains the amount of nodes inside the node group.
instanceType is the desired AWS EC2 instance type for the node group. All nodes
will be of that instance type.
Delete a cluster
kubectl
kubectl command cheatsheet
apiVersion: apps/v1
kind: Deployment
metadata:
name: <deployment-name>
spec:
replicas: 1
selector:
matchLabels:
app: <app-name>
template:
https://gist.github.com/ziritrion/1842c8a4c4851602a8733bba19ab6050 7/9
12/15/22, 12:09 PM Cheatsheet for various container and VM thingies · GitHub
metadata:
labels:
app: <app-name>
spec:
containers:
- name: <my-container>
image: my-component-image:some-tag
resources:
limits:
memory: "128Mi"
cpu: "100m"
ports:
- containerPort: 9696
env:
- name: TF_SERVING_HOST
value: <service-name>.<namespace>.svc.cluster.local:8500
spec.replicas states how many pods should be replicated in the deployment. This
example file only states 1 replica.
spec.selector defines how the deployment finds which pods to manage.
spec.selector.matchLabels is a rule that will match a label in the pod template (the
label in this case is app:<app-name> )
spec.template contains the blueprint for the pods:
metadata in this example contains the labels we use for the pods so that the
deployment can find and manage them.
..spec.containers contains a plethora of info:
name is the name of the containers inside the pod.
env contains names and values for nvironment variables, useful for apps to
be able to find other containers by their internal cluster URL.
When defining a service, Kubernetes publishes a DNS entry inside the
Cluster to make it possible for pods to find other pods. These DNS
entries follow the <service-name>.<namespace>.svc.cluster.local:
<port> format.
https://gist.github.com/ziritrion/1842c8a4c4851602a8733bba19ab6050 8/9
12/15/22, 12:09 PM Cheatsheet for various container and VM thingies · GitHub
apiVersion: v1
kind: Service
metadata:
name: <service-name>
spec:
type: LoadBalancer
selector:
app: <app-name>
ports:
- port: 80
targetPort: 9696
spec.ports contains both the port of the service ( port ) as well as the port of the
deployment ( targetPort ).
https://gist.github.com/ziritrion/1842c8a4c4851602a8733bba19ab6050 9/9