About Docker
Docker refers to containerized technology, which is used to support the creation and experimentation of Linux Container. With Docker, you can use containers as lightweight, modular virtual machines, and you get a high degree of flexibility to efficiently create, deploy, and replicate containers, and migrate them from one environment to another.
Docker official website: http://www.docker.com
Github Docker Source: Github.com/docker/docker
Basic Features :
- Application based on C/s architecture
- Modular
- Layer and mirror version control
- Support rollback
- Rapid deployment
Application Scenarios for Docker
- Automated packaging and publishing of WEB applications.
- Automated testing and continuous integration, release.
- Deploy and tune databases or other background applications in a service-oriented environment.
- Build your own PAAs environment by compiling from scratch or by extending your existing OpenShift or cloud foundry platform.
Docker infrastructure Diagram :
- Docker uses the client-server (c/s) architecture pattern to manage and create Docker containers using remote APIs
- Docker containers are created with Docker images
- Docker_host: The host that really runs the container
- Containers: A container, one or a set of applications that run independently
- Images: Mirroring, template for creating Docker containers
- Registry: Mirrored Warehouse
mirror image differs from container container :
- The mirror is static and does not run
- The container is dynamic and has a life cycle.
Docker Container Mirroring Station: hub.docker.com
Docker Object:
- Image
- Containers
- Networks
- Volumes
- Plugins
Docker installation installs Docker directly on CentOS
Uninstall the previous version before installing it first:
$ sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-selinux \ docker-engine-selinux \ docker-engine
To install the Docker dependency package:
$ sudo yum install -y yum-utils \ device-mapper-persistent-data \ lvm2
Add a Docker source (if the official Docker download is too slow, you can use Ali's image source: Http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo):
$ sudo yum-config-manager \ --add-repo \ download.docker.com/linux/centos/docker-ce.repo
Installing Docker:
$ sudo yum install docker-ce
After you install the direct boot docker:
~]# systemctl start docker
Use docker version
to see the version where we installed Docker
~]# docker version Client: Version: 18.03.1-ce API version: 1.37 Go version: go1.9.5 Git commit: 9ee9f40 Built: Thu Apr 26 07:20:16 2018 OS/Arch: linux/amd64 Experimental: false Orchestrator: swarmServer: Engine: Version: 18.03.1-ce API version: 1.37 (minimum version 1.12) Go version: go1.9.5 Git commit: 9ee9f40 Built: Thu Apr 26 07:23:58 2018 OS/Arch: linux/amd64 Experimental: false
Quickly build docker environments with vagrant + Virtual box
Vagrant Introduction
Vagrant is a ruby-based tool for creating and deploying virtualized development environments. It uses Oracle's Open source VirtualBox virtualization system to create automated virtual environments using chef. We can use it to do the following:
- Create and delete virtual machines
- Configure virtual machine Run parameters
- Managing Virtual Machine Run state
- Automatically configure and install the development environment
- Packaging and distributing virtual machine run environments
The operation of Vagrant relies on a specific virtualization technology, the most common of which are VirtualBox and VMware Two, early, vagrant only supported VirtualBox, and later added VMware support.
Vagrant Installation and use
Vagrant is based on other virtualization products to create virtual machines, here we select the Open Source Product virtual box, we first install virtual box and vagrant:
- Virtual box:www.virtualbox.org/
- Vagrant:www.vagrantup.com/downloads.html
Once downloaded, use the vagrant init centos/7
generate default Vagrntfile, then use to vagrant up
automatically create the virtual machine, we need to change the next vagrantfile in order to configure the Docker environment, when the virtual machine is created automatically install the Docker environment (configuration config.vm.provision "shell"
Options) and configure the size and network of the virtual machines as required.
My vagrantfile is configured as follows
#-*-Mode:ruby-*-# vi:set ft=ruby:vagrant.require_version ">= 1.6.0" boxes = [{: name = "Docker-1", : eth1 = "172.16.56.11",: Mem = "1024x768", CPU = "1"}]vagrant.configure (2) Do |config| Config.vm.box = "CENTOS/7" Boxes.each do |opts| Config.vm.define Opts[:name] Do |config| Config.vm.hostname = Opts[:name] Config.vm.provider "vmware_fusion" do |v| v.vmx["memsize"] = Opts[:mem] v.vmx["Numvcpus"] = Opts[:cpu] End Config.vm.provider "VirtualBox" do |v| v.customize ["MODIFYVM",: ID, "--memory", Opts[:mem]] v.customize ["MODIFYVM",: ID, "--cpus", Opts[:cpu]] End Config.vm.network:p ublic_network, ip:opts[:eth1] End end# Config.vm.synced_folder ". /sync ","/home/vagrant/sync "config.vm.provision" Shell ", inline: <<-shell yum-y install wget wget-o/E Tc/yum.repos.d/centos-base.repo Http://mirrors.aliyun.com/repo/Centos-7.repo Yum Makecache Yum INstall-y yum-utils device-mapper-persistent-data lvm2 yum-config-manager--add-repo http://mirrors.aliyun.com/docker -ce/linux/centos/docker-ce.repo Yum Makecache fast yum-y install Docker-ce sudo systemctl start docker SH Ellend
Then use vagrant up
Create it
Λvagrant upbringing machine ' docker-1 ' up with ' VirtualBox ' provider...==> docker-1: Importing base box ' CENTOS/7 ' ... [ Kprogress:20%[kprogress:40%[kprogress:90%[k==> docker-1: Matching MAC address for NAT networking...==> docker-1: Checking if box ' CENTOS/7 ' is up to date...==> docker-1: Setting The name of the Vm:docker-1_docker-1_1534247086153_8 3300==> docker-1: Clearing any previously set network interfaces...==> docker-1: Preparing Network interfaces based On configuration ... docker-1: Adapter 1:nat docker-1: Adapter 2:bridged==> docker-1: Forwarding ports ... doc Ker-1: (Guest) = 2222 (host) (Adapter 1) ==> docker-1: Running ' pre-boot ' VM customizations...==> docker-1: Bo Oting vm...==> docker-1: Waiting to boot. This could take a few minutes ... docker-1: ssh address:127.0.0.1:2222 docker-1: ssh username:vagrant docker-1: SS H auth method:private key docker-1: docker-1: Vagrant insecure key detected. VagraNT would automatically replace docker-1: this with a newly generated keypair for better security. Docker-1: docker-1: Inserting generated public key within Guest...==> Docker-1: Machine booted and ready!==> doc Ker-1: Checking for guest additions in VM ...
In this process, vagrant will help us create a CentOS 7 virtual machine and install the Docker environment, using the vagrant ssh
Direct login virtual machine
λ vagrant sshLast login: Wed Aug 15 15:54:32 2018 from 10.0.2.2[vagrant@docker-1 ~]$ sudo docker versionClient: Version: 18.06.0-ce API version: 1.38 Go version: go1.10.3 Git commit: 0ffa825 Built: Wed Jul 18 19:08:18 2018 OS/Arch: linux/amd64 Experimental: falseServer: Engine: Version: 18.06.0-ce API version: 1.38 (minimum version 1.12) Go version: go1.10.3 Git commit: 0ffa825 Built: Wed Jul 18 19:10:42 2018 OS/Arch: linux/amd64 Experimental: false[vagrant@docker-1 ~]$
Vagrantfile has an item Config.vm.synced_folder
can configure local folder synchronization to the virtual machine, Mount local folder to the virtual machine need vboxadditions support, This can be installed after the virtual machine, you can also refer to the use of Vagrant-vbguest plug-in, this feature is more suitable for developers, you can write code locally and debug code in a Linux environment to run.
Docker and vagrant are only recently started to learn, what is wrong or wrong place also ask you to correct, what do not understand can also communicate together.