Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Containers

dainank edited this page Apr 17, 2023 · 6 revisions

A Container

method of virtualizing server

In our case, we will use them to host microservices. Specifically, a container virtualizes the operating system and the hardware. We can therefore abstract the resources required per microservice. They essentially make it cost-effective to run microservices. The end-goal is to have many containers running on a Kubernetes cluster.

An Image

a bootable snapshot of a server

Thus including everything needed to run:

  • all src code
  • dependencies
  • assets

Images are immutable once created while containers are mutable. The contents of an image's file system can be modified. Essentially images are dormant, ready-to-be booted (instantiated) as a container.

Docker

a tool to package and publish microservices

Docker can be used to:

  • package microservice into an image
  • publish image to private container registry
  • run microservice in container

Dockerfiles

specification for an image created by Docker (script file with instructions on how to create image)

  • FROM - base image(see https://hub.docker.com/) for our derived new image
  • WORKDIR - ?
  • COPY - copy local files into new image
  • RUN - commands to run in image build process
  • CMD - which command to run when container instantiated

You can package a microservice through the following command for example:

docker build -t video-streaming-v1 --file Dockerfile .

Additional Commands:

  • docker image list - view all images
  • docker container list - view all containers
  • docker logs [id] - view logs
  • docker exec -it <container-id> sh - shell into container (debug)
  • docker stop <container-id> - stop container
  • docker rm <container-id> - delete container

Additional Flags:

  • -d - run in detatched mode; run in background
  • -p - bind ports HOST:CONTAINER (port forwarding)
  • -e - set env vars

Publishing Containers

  1. Create private container registry (Microsoft Azure)
  2. Authenticate with docker login
  3. Tag image with docker tag
  4. Upload with docker push
  5. Test run with docker run