Skip to content

Instantly share code, notes, and snippets.

@mottyc
Last active June 8, 2017 13:10
Show Gist options
  • Save mottyc/32efc9d888247e4b2dc013f8e3401acb to your computer and use it in GitHub Desktop.
Save mottyc/32efc9d888247e4b2dc013f8e3401acb to your computer and use it in GitHub Desktop.
Script to install docker engine on Ubuntu server

Attach volume on host OS

This Gist describe how to create and attach virtual disk to the VM The source article can be found here.

Initialize new data disk in Linux

  • SSH to the VM: ssh -i ~/ssh/ssh_identity_file user@server_ip
  • Find the SCSI device identifier (of the attached volume) using lsscsi
  • Install lsscsi if needed: sudo yum install lsscsi

For the next steps, we assume the new volume is called /dev/sdc

  • sudo fdisk /dev/sdc
  • type ''n'' to create partition
  • select ''p'' for primary partition
  • type 1 to make it the first partition
  • Type ''p'' to see details about the disk
  • Type ''w'' to write settings for the new disk

Create a file system on the newly created disk and mount it

  • sudo mkfs -t ext4 /dev/sdc1
  • Make a directory to mount the new file system: sudo mkdir /datadrive
  • Mount the drive to the directory: sudo mount /dev/sdc1 /datadrive

Add the new drive to /etc/fstab

  • Find the UUID of the new drive: sudo -i blkid
  • Edit /etc/fstab in text editor: sudo nano /etc/fstab
  • Add line to /etc/fstab: (replace UUID value) UUID=33333333-3b3b-3c3c-3d3d-3e3e3e3e3e3e /datadrive ext4 defaults,nofail 1 2

Test if file system mounted properly:

  • Unmount the directory: sudo umount /datadrive
  • Mount back the directory: sudo mount /datadrive

Make writable:

  • Make the drive writable: sudo chmod go+w /datadrive
#!/bin/sh
#
# Docker install script
#
# Run this script with Administration priviledges (sudo)
#
echo "------------ Install pre-requisites ---------------------"
# Install packages to allow apt to use a repository over HTTPS:
apt-get install apt-transport-https ca-certificates curl software-properties-common
# Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add
# Print the key fingerprint to verify it is: 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
apt-key fingerprint 0EBFCD88
echo "------------ Set and update repository ------------------"
# Set up the stable repository:
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update
echo "------------ Install and test docker -------------------"
# Install the latest version of Docker:
apt-get install docker-ce
# Verify that Docker is installed correctly by running the hello-world image
sudo docker run hello-world
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment