VIRTUAL MACHINES
Virtual machines (VMs) are an abstraction of physical hardware turning one server into many servers. The hypervisor allows multiple VMs to run on a single machine. Each VM includes a full copy of an operating system, the application, necessary binaries and libraries - taking up tens of GBs. VMs can also be slow to boot.
CONTAINERS
Containers are an abstraction at the app layer that packages code and dependencies together. Multiple containers can run on the same machine and share the OS kernel with other containers, each running as isolated processes in user space. Containers take up less space than VMs (container images are typically tens of MBs in size), can handle more applications and require fewer VMs and Operating systems.
![]() |
Types of Containers
Linux Containers (LXC) — The original Linux container technology is Linux Containers, commonly known as LXC. LXC is a Linux operating system level virtualization method for running multiple isolated Linux systems on a single host.
Docker — Docker started as a project to build single-application LXC containers, introducing several changes to LXC that make containers more portable and flexible to use. It later morphed into its own container runtime environment. At a high level, Docker is a Linux utility that can efficiently create, ship, and run containers.
Benefits of Containers
- Reduced IT management resources
- Reduced size of snapshots
- Quicker spinning up apps
- Reduced & simplified security updates
- Less code to transfer, migrate, upload workloads
Popular Container Providers
1) Linux Containers- LXC
- LXD
- CGManager
3) Windows Server Containers
|
Virtual Machines |
Containers |
|
|
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh$ sudo docker version$ sudo docker run hello-worldvagrant@vagrant-ubuntu-trusty-64:~$ sudo docker run hello-world
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "process_linux.go:297: copying bootstrap data to pipe caused \"write init-p: broken pipe\"": unknown.$ sudo docker imagesdocker run [OPTIONS] IMAGE [COMMAND] [ARG...]docker run -i -t ubuntu /bin/bash- If you do not have the ubuntu image locally, Docker pulls it from your configured registry, as though you had run docker pull ubuntu manually.
- Docker creates a new container, as though you had run a docker container create command manually.
- Docker allocates a read-write filesystem to the container, as its final layer. This allows a running container to create or modify files and directories in its local filesystem.
- Docker creates a network interface to connect the container to the default network, since you did not specify any networking options. This includes assigning an IP address to the container. By default, containers can connect to external networks using the host machine’s network connection.
- Docker starts the container and executes /bin/bash. Because the container is running interactively and attached to your terminal (due to the -i and -t flags), you can provide input using your keyboard while the output is logged to your terminal.
- When you type exit to terminate the /bin/bash command, the container stops but is not removed. You can start it again or remove it.
docker run nginxdocker stop -t CONTAINER [or] docker stop --time CONTAINERdocker stop dreamy_albattanidocker rm [OPTIONS] CONTAINER [CONTAINER...]docker rm /redisThis removes the container referenced under the link /redis.
docker rm --link /webapp/redisThis removes the underlying link between /webapp and the /redis containers on the default bridge network, removing all network communication between the two containers. This does not apply when --link is used with user-specified networks.
docker rm --force redisThis command force-removes a running container.The main process inside the container referenced under the link redis will receive SIGKILL, then the container will be removed.
docker rm $(docker ps -a -q)This command deletes all stopped containers. The command docker ps -a -q above returns all existing container IDs and passes them to the rm command which deletes them. Running containers are not deleted.
docker rm -v redisThis command removes the container and any volumes associated with it. Note that if a volume was specified with a name, it will not be removed.
docker create -v awesome:/foo -v /bar --name hello redisdocker rm -v helloIn this example, the volume for /foo remains intact, but the volume for /bar is removed. The same behavior holds for volumes inherited with --volumes-from.
docker images [OPTIONS] [REPOSITORY[:TAG]]docker images
docker images [REPOSITORY]If you specify repository but no TAG , the docker images command lists all images in the given repositorydocker images [REPOSITORY[:TAG]]If both REPOSITORY and TAG are provided, only images matching that repository are listed. If nothing matches the list is empty.
docker images --no-truncThis will list images with full length IDs and don't truncate the output.
docker images --digestsImages that use the v2 or later format have a content-addressable identifier called a digest. As long as the input used to generate the image is unchanged, the digest value is predictable. To list image digest values, use the --digests flagWhen pushing or pulling to a 2.0 registry, the push or pull command output includes the image digest. You can pull using a digest value. You can also reference by digest in create, run, and rmi commands, as well as the FROM image reference in a Dockerfile.
The filtering flag (-f or --filter) format is of “key=value”. If there is more than one filter, then pass multiple flags (e.g., --filter "foo=bar" --filter "bif=baz")The currently supported filters are:dangling (boolean - true or false)label (label=<key> or label=<key>=<value>)before (<image-name>[:<tag>], <image id> or <image@digest>) - filter images created before given id or referencessince (<image-name>[:<tag>], <image id> or <image@digest>) - filter images created since given id or referencesreference (pattern of an image reference) - filter images whose reference matches the specified patterndocker images --filter "dangling=true"This will display untagged images that are the leaves of the images tree (not intermediary layers). These images occur when a new build of an image takes the repo:tag away from the image ID, leaving it as <none>:<none> or untagged. A warning will be issued if trying to remove an image when a container is presently using it. By having this flag it allows for batch cleanup.You can use this in conjunction with docker rmidocker rmi $(docker images -f "dangling=true" -q)Docker warns you if any containers exist that are using these untagged images.
Format the output
The formatting option (--format) will pretty print container output using a Go template
.ID Image ID
.Repository Image repository
.Tag Image tag
.Digest Image digest
.CreatedSince Elapsed time since the image was created
.CreatedAt Time when the image was created
.Size Image disk size
Examples
docker images --format "{{.ID}}: {{.Repository}}"
docker images --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}"
#docker images
docker rmi [OPTIONS] IMAGE [IMAGES...]docker pull [OPTIONS] NAME[:TAG|@DIGEST]
























