Search code examples
dockerboot2docker

Automation of docker commands


I want to do the automation of docker commands so that ,

I can verify the docker commands to verify the sanity .

I just need to know if any plugins are available for this purpose, or If I have to start from the scratch in which language I can write ? How to start it initially?


Solution

  • If you are looking for a way to automate the creation and provisioning of a VM with Docker, you should take a look at Vagrant (and maybe Puppet).

    Vagrant

    Vagrant is a tool to create VMs. You find it at http://www.vagrantup.com/. It works basically like this: You install Vagrant and a VM like VirtualBox. Then you create a file called Vagrantfile which describes your VM. For my Docker environment, I am using a file which looks like this:

    VAGRANTFILE_API_VERSION = "2"
    
    Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    
      config.vm.box = "99designs/ubuntu-saucy-docker"
      config.vm.box_url = "https://vagrantcloud.com/99designs/ubuntu-saucy-docker/version/2/provider/virtualbox.box"
    
      config.vm.network :forwarded_port, guest: 8080, host: 8080
      config.vm.network :forwarded_port, guest: 4243, host: 4243
      config.vm.network :forwarded_port, guest: 9000, host: 9000
      config.vm.network :forwarded_port, guest: 5000, host: 5000
    
      config.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777","fmode=777"]
    
      config.vm.provider :virtualbox do |vb|
        vb.customize ["modifyvm", :id, "--memory", "2024"]
        vb.customize ["modifyvm", :id, "--cpus", "2"]
      end
    
      config.vm.provision "shell", path: "add_docker_to_sudo.sh"
      config.vm.provision "shell", path: "disable_friewall.sh"
      config.vm.provision "shell", path: "set_nls_lang.sh"
    
    end
    

    The file describes your VM. It defines the image installed to your VM (maybe the boot2docker image), open ports, folders of your host available in your VM and so on. It can also define scripts which are run when the VM is up. In my example, I am running three shell scripts when the VM is up to add Docker to sudo, disable the firewall (hahaha) and set a environment variable I need. You can to anything here. If shell commands are not enough, take a look at (e.g.) Puppet (http://puppetlabs.com/).

    You just call vagrant up to create your VM and vagrant ssh to get access to it. You can just destroy it and create it again anytime you need it.