Docker vs Virtual Machine - docker

I have read documents that are about dockers and VMs.I guess that our environments like that dev,prod run on virtual machines in a server.Each of them runs on different virtual machine but single computer(server).Also,each virtual machine contains docker.Every docker contains containers.In this containers, application image file is hold.For example; in virtual machineB ,containerB includes image for our application.Am i right?
Can a docker contains many containers? Why we need many containers in a docker? Can anyone explain docker,virtual machine,environments and image files?How these enviroments runs server?

From https://www.docker.com/what-container:
A container image is a lightweight, stand-alone, executable package of a piece of software that includes everything needed to run it.
Docker is the service to run multiple containers on a machine (node) which can be on a vitual machine or on a physical machine.
A virtual machine is an entire operating system (which normally is not lightweight).
If you have multiple applications and those require different configurations which are in conflict with each other you can either deploy them on different machines or on the same machine using docker containers, because containers are isolated from each other.
So in short containers can make your application deployment and management easier.

Related

Docker-machine vs Vagrant? [duplicate]

Every Docker image, as I understand, is based on base image - for example, Ubuntu.
And if I want to isolate any process I should deploy ubuntu docker base image (where is difference with Vagrant here?), and create a necessary subimage after it installing on ubuntu image?
So, if Ubuntu is launched on Vagrant and on Docker, where is practice difference?
And if to use docker provider in Vagrant - where here is difference between Vagrant and Docker?
And, in Docker is it possible to isolate processes on some PC without base image without it's sharing to another PC?
Vagrant is a utility to help you automate setting up VMs. Docker is a utility that helps you use containerization in linux.
A virtual machine runs a whole system, and emulates hardware. Containers section off processes in a single running kernel without emulating hardware.
Both a VM and a Docker image may be Ubuntu 14.04, but with the Docker image you don't need to run the whole OS.
For example, if I want to run an nginx container based on ubuntu, I'd end up with only the nginx process running. No upstart/systemd/init is needed. A VM would run an init system, manage its own networking, and run other services as well. The container image approach that uses a linux distro base is mostly for convenience.
It is entirely possible to run Docker containers with very minimal images. A statically compiled binary alone in an image is all you'd need to run a container.
Vagrant : Vagrant is a project that helps the spawning of virtual machines. It started as an command line of VirtualBox, something similar to Gemfile for VM's. You can choose the base image to start with, network, IP, share folders and put it all in a file that anyone can reuse to spawn the same configured machine. Vagrant has different extensions, provisioning options and VM providers. You can run a VirtualBox, VMware and it is extensible enough to be able to create instances on EC2.
Docker : Docker, allows to package an application with all of its dependencies into a standardized unit of software development. So, it reduces a friction between developer, QA and testing. It dynamically change your application, adding new capabilities every single day, scaling out services to quickly changing the problem areas. Docker is putting itself in an excited place as the interface to PaaS be it networking, discovery and service discovery with applications not having to care about underlying infrastructure. Yes, their are still issues with docker in production, but, hopefully, we'll see the solutions to those problems, as docker team and contributors working hard on those issues. As Docker Volume driver allows third-party container data management solutions to provide data volumes for containers which operate on data, such as database, key-value stores, and other stateful applications. The latest version is coming with much more flexibility, complete orchestration build-in, advanced networking, secrets management, etc. As you can see one, rexray, as volume plugin and provides advanced storage functionality. emccode/rexray We're finally starting to agree on more than just images and run time.

Missuse Docker Container as VM

I've read that you shouldn't ssh into a docker container. But why? I'd like to use a docker container as a replacement for a normal VM. What are the disadvantages? I know that this will create a lot of layers. But I could flatten my container on a regular base.
Can I use the container as a regular vm and what is the "worst case" that can happen?
Docker containers are optimized around running single processes. Virtual machines are optimized around running entire operating systems.
At a technical level you generally can run something that looks like a full VM inside a Docker container, but it's a lot of hand setup. For instance, a typical systemd setup wants to manage several host devices and kernel-level configuration options, and your choices to run systemd are either (a) let it manage the host and possibly conflict with the host's systemd, or (b) manually figure out which unit files you can't run and disable them. All of the prebuilt Docker images run only single services (just MySQL, just Nginx, just a Python runtime, ...) and so you're also giving up this ecosystem.
A VM certainly gives up some amount of efficiency by virtualizing hardware devices and running multiple OS kernels, but if you really want to run a VM, it's not a huge performance loss; just run a VM if that's the model you want to use.
No you can't use it as a replacement for a VM since you can only have one entrypoint on a docker container. You can not expose multiple services on multiple ports like you would on a regular virtual machine.

Contents of Docker images

What exaxtly a Docker image may contain? As it is mantioned that image can have all possible dependecies require for a microservice, so how do an image intract with databases?
A docker image just contains the software and its dependencies. Then you use that image to create one or multiple containers using that image. When creating the container you can inject configuration and mount up external persistent storage if needed.
Think of running containers as virtual machines with their own ip addresses except that the container itself do not run an actual OS. The processes will actually run on the host OS, but they are completely isolated by the kernel.
I docker image mainly contains files. Often they contain file structure from an an OS. For example ubuntu, centos, alpine linux etc.. These files are only there to support the application and provide the most common tools.

How can I make a local docker container?

I installed Docker and kitematic. I had VirtualBox before that and used many machines on Vbox. Docker is working, I can pull containers and other stuff like that. Like this link : https://docs.docker.com/mac/started/
I can add containers by:
<i> docker run docker/whalesay cowsay boo </i>
I want to know if there is any way that I can import some of my Vbox machines into docker as a Container locally?
I have ova and ovf file in my local pc. I don't wanna get involved with online containers! Is there any way to accomplish this.
Thank you.
Looks like you have some confusion on the concept of a container.
A container is not a virtual machine.
You can't import virtual machines into Docker. What you can do is build and run a Docker container which eliminates the need for a virtual machine (depending on your use case of course).
You can find a good explanation about the difference between a container and a virtual machine here.
TL;DR:
Both virtual machines and containers allow you to run multiple applications on a shared hardware.
When using virtual machines, the hardware is shared among all applications, however each application runs on a separate operating system.
When using containers, both the hardware AND the operating system are shared, and each application runs in a separate container.
This is in no way an exhaustive explanation regarding Docker containers - there are MANY more advantages to using Docker instead of a virtual machine (portability, consistency, infrastructure-as-code). This is just the main difference between them.

Docker vs Vagrant

Every Docker image, as I understand, is based on base image - for example, Ubuntu.
And if I want to isolate any process I should deploy ubuntu docker base image (where is difference with Vagrant here?), and create a necessary subimage after it installing on ubuntu image?
So, if Ubuntu is launched on Vagrant and on Docker, where is practice difference?
And if to use docker provider in Vagrant - where here is difference between Vagrant and Docker?
And, in Docker is it possible to isolate processes on some PC without base image without it's sharing to another PC?
Vagrant is a utility to help you automate setting up VMs. Docker is a utility that helps you use containerization in linux.
A virtual machine runs a whole system, and emulates hardware. Containers section off processes in a single running kernel without emulating hardware.
Both a VM and a Docker image may be Ubuntu 14.04, but with the Docker image you don't need to run the whole OS.
For example, if I want to run an nginx container based on ubuntu, I'd end up with only the nginx process running. No upstart/systemd/init is needed. A VM would run an init system, manage its own networking, and run other services as well. The container image approach that uses a linux distro base is mostly for convenience.
It is entirely possible to run Docker containers with very minimal images. A statically compiled binary alone in an image is all you'd need to run a container.
Vagrant : Vagrant is a project that helps the spawning of virtual machines. It started as an command line of VirtualBox, something similar to Gemfile for VM's. You can choose the base image to start with, network, IP, share folders and put it all in a file that anyone can reuse to spawn the same configured machine. Vagrant has different extensions, provisioning options and VM providers. You can run a VirtualBox, VMware and it is extensible enough to be able to create instances on EC2.
Docker : Docker, allows to package an application with all of its dependencies into a standardized unit of software development. So, it reduces a friction between developer, QA and testing. It dynamically change your application, adding new capabilities every single day, scaling out services to quickly changing the problem areas. Docker is putting itself in an excited place as the interface to PaaS be it networking, discovery and service discovery with applications not having to care about underlying infrastructure. Yes, their are still issues with docker in production, but, hopefully, we'll see the solutions to those problems, as docker team and contributors working hard on those issues. As Docker Volume driver allows third-party container data management solutions to provide data volumes for containers which operate on data, such as database, key-value stores, and other stateful applications. The latest version is coming with much more flexibility, complete orchestration build-in, advanced networking, secrets management, etc. As you can see one, rexray, as volume plugin and provides advanced storage functionality. emccode/rexray We're finally starting to agree on more than just images and run time.

Resources