Overview
Last updated
Was this helpful?
Last updated
Was this helpful?
Vagrant 與 Docker 相同之處都是要解決環境相依的問題,但是對象不同。Vagrant 焦距在開發當下,只要我的專案含有 Vagrantfile 及機器裝有 VirtualBox,開發者在任何一台機器都可以開發。Docker 則焦距在應用服務的部署,但也涉及開發的方法,在開發時就會直接用 container 來實作。 兩者可以各別使用,但又可相輔相,一切取決於使用情境。
如果你僅僅是想管理虛擬機,那麼你應該使用vagrant。如果你想快速開發和部署應用,那麼應該使用docker。vagrant是一款管理虛擬機的工具,而docker是一款通過將應用打包到輕量級容器,而實現構建和部署的工具。
Vagrant is a tool for managing developing environment. Docker is a tool for building and deploying applications by packaging them into lightweight containers. —
Vagrant enables users to create and configure lightweight, reproducible, and portable development environments. It is a tool for building and managing virtual machine environments in a single workflow.
With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases production parity, and makes the "works on my machine" excuse a relic of the past.
The basic unit is box
. The name of a box is consist of username
and boxname
. For example, ubuntu/trusty64
is the official Ubuntu 16.04. One box is possible to have multiple version, e.g. ubuntu/trusty63:v1234
.
Box is an image, Project is a container.
Unlike docker, vagrant use virtual box (possible others) to create a VM. It provides a way to reproduce the actual production environment which may contains multiple containers.
Imagine that you are developing a services in a huge system and others are developing the rest, how can you test your code independently (their code may be buggy under development)?
In this situation, DevOps can create a stable system snapshot and reproduce it by vagrant (repeat! vagrant just a tool to manage vm). Every developer can have this box and use it in their own development environment. This environment is the same for everyone (cross-platform). They do not need to worry whether their testing will affect each other. Of course, they interaction (API) should be designed by contract. But under this contract, they can work independently even in testing. After the works are done, they can put all the components together in the same environment (box) to test their integration.
On the other, if your production os is ubuntu 16.04, will you be confident that it will work in ubuntu 18.04? Of course not! In this situation, you can just replace the the base image in the scripts and then you can easily test your codes.