Class: SmartCloud::Docker
Class Method Summary collapse
-
.running? ⇒ Boolean
Below methods are non ssh methods and should be executed on the server only.
Instance Method Summary collapse
- #add_ufw_rules ⇒ Object
-
#initialize ⇒ Docker
constructor
A new instance of Docker.
-
#install ⇒ Object
Installing Docker!.
- #remove_ufw_rules ⇒ Object
-
#uninstall ⇒ Object
Uninstalling Docker!.
Methods included from Logger
configure_logger_for, included, #logger, logger_for
Constructor Details
#initialize ⇒ Docker
Returns a new instance of Docker.
4 5 |
# File 'lib/smart_cloud/docker.rb', line 4 def initialize end |
Class Method Details
.running? ⇒ Boolean
Below methods are non ssh methods and should be executed on the server only.
125 126 127 128 129 130 131 132 |
# File 'lib/smart_cloud/docker.rb', line 125 def self.running? if system("docker info", [:out, :err] => File::NULL) true else puts "Error: Docker daemon is not running. Have you installed docker? Please ensure docker daemon is running and try again." false end end |
Instance Method Details
#add_ufw_rules ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/smart_cloud/docker.rb', line 72 def add_ufw_rules puts '-----> Add the following rules to the end of the file /etc/ufw/after.rules and reload ufw using - sudo ufw reload' puts '# BEGIN UFW AND DOCKER *filter :ufw-user-forward - [0:0] :DOCKER-USER - [0:0] -A DOCKER-USER -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -A DOCKER-USER -m conntrack --ctstate INVALID -j DROP -A DOCKER-USER -i eth0 -j ufw-user-forward -A DOCKER-USER -i eth0 -j DROP COMMIT # END UFW AND DOCKER' # puts "-----> Adding UFW rules for Docker" # interface_name = system("ip route show | sed -e 's/^default via [0-9.]* dev \(\w\+\).*/\1/'") # puts interface_name # system("sed '/^# BEGIN UFW AND DOCKER/,/^# END UFW AND DOCKER/d' '/etc/ufw/after.rules'") # system("sudo tee -a '/etc/ufw/after.rules' > /dev/null <<EOT # # BEGIN UFW AND DOCKER # *filter # :ufw-user-forward - [0:0] # :DOCKER-USER - [0:0] # -A DOCKER-USER -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT # -A DOCKER-USER -m conntrack --ctstate INVALID -j DROP # -A DOCKER-USER -i eth0 -j ufw-user-forward # -A DOCKER-USER -i eth0 -j DROP # COMMIT # # END UFW AND DOCKER # EOT") # system("sudo ufw reload") end |
#install ⇒ Object
Installing Docker!
Example:
=> Installation Complete
Arguments:
none
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/smart_cloud/docker.rb', line 14 def install ssh = SmartCloud::SSH.new puts "-----> Installing Docker" commands = [ "sudo apt-get -y update", "sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common", "curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -", "sudo apt-key fingerprint 0EBFCD88", "sudo add-apt-repository \"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable\"", "sudo apt-get -y update", "sudo apt-get -y install docker-ce", "sudo usermod -aG docker $USER", "docker run --rm hello-world", "docker rmi hello-world" ] ssh.run commands puts "-----> Installing Docker Compose" commands = [ "sudo curl -L --fail https://github.com/docker/compose/releases/download/1.24.0/run.sh -o /usr/local/bin/docker-compose", "sudo chmod +x /usr/local/bin/docker-compose", "docker-compose --version", "sudo curl -L https://raw.githubusercontent.com/docker/compose/1.24.0/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose" ] ssh.run commands self.add_ufw_rules puts "-----> Installation Complete" end |
#remove_ufw_rules ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/smart_cloud/docker.rb', line 105 def remove_ufw_rules puts '-----> Remove the following rules at the end of the file /etc/ufw/after.rules and reload ufw using - sudo ufw reload' puts '# BEGIN UFW AND DOCKER *filter :ufw-user-forward - [0:0] :DOCKER-USER - [0:0] -A DOCKER-USER -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -A DOCKER-USER -m conntrack --ctstate INVALID -j DROP -A DOCKER-USER -i eth0 -j ufw-user-forward -A DOCKER-USER -i eth0 -j DROP COMMIT # END UFW AND DOCKER' # puts "-----> Removing UFW rules for Docker" # system("sed '/^# BEGIN UFW AND DOCKER/,/^# END UFW AND DOCKER/d' '/etc/ufw/after.rules'") # system("sudo ufw reload") end |
#uninstall ⇒ Object
Uninstalling Docker!
Example:
=> Uninstallation Complete
Arguments:
none
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/smart_cloud/docker.rb', line 53 def uninstall ssh = SmartCloud::SSH.new puts "-----> Uninstalling Docker Compose" ssh.run "sudo rm /usr/local/bin/docker-compose" puts "-----> Uninstalling Docker" commands = [ "sudo apt-get purge docker-ce", "sudo rm -rf /var/lib/docker" ] ssh.run commands self.remove_ufw_rules puts "-----> Uninstallation Complete" puts "-----> You must delete any edited configuration files manually." end |