Docker 101

This is notes from the youtube video Docker Containers 101 by Network Chuck. If any information in the video was oversimplified, that would be reflected here as well.

First, what is a virtual machine?

Before virtual machines, you would, for example, install a single operating system on a server. The issue with this is that if we wanted another operating system to be running at the same time on this server, that’d be difficult and we would just get another physical server.

Virtualization

We use a hypervisor to carve up the server’s resources to be like multiple servers, which may or may not be running different operating systems.


What is docker?

Essentialy, we are replacing a VM (virtual machine), and instead of virtualizing the hardware, we are virtualizing the operating system itself.

What does virtualizing the operating system mean?

Instead of splitting up the hardware to have different operating systems run, we can take advantage of the fact that the other operating systems we would run use the same kernel as the base operating system. This allows docker containers (defined as microcomputers in the video) to be lightweight and fast. The big caveat is that the containers’ operating systems have to use the same kernel as the base operating system (so no Windows container on a Linux kernel).

Why would we want this?

Containers help us remove the “it works on my machine” issue that a lot of developers run into. Additionally, modularization is a big part of software development, and docker containers are one big step forward towards streamlining the development process by isolating various parts of the system or project or product we are making.


Commands

Pull an image:

docker pull someimage


Create and run a container in detached/background mode (-d) and a virtual terminal (-t):

docker run -t -d --name mycontainer someimage


Connect to a docker container with interactive virtual terminal (-it) through bash:

docker exec -it mycontainer /bin/bash


Check running containers:

docker ps


Stop a running container:

docker stop mycontainer


Start a stopped container:

docker start mycontainer


Check CPU/RAM/etc. stats:

docker stats

 Date: August 28, 2024
 Tags:  lecture

Previous:
⏪ 6.5830 Lecture 1 (WIP)