Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Install Docker PPA on Ubuntu 16.04
# NOT FOR SHELL SCRIPT, but rather just for quick copy paste
# this is a copy-paste version with defaults of the full shell script which is below this one in gist.
apt-get -y install apt-transport-https ca-certificates curl && \
curl -fsSL | sudo apt-key add - && \
add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable" && \
service lxcfs stop && apt-get remove -y -q lxc-common lxcfs lxd lxd-client && \
apt-get update -q && \
apt-get install -y -q docker-ce && \
printf '{ "userns-remap" : "default" , "storage-driver" : "overlay2" }' > /etc/docker/daemon.json && \
systemctl restart docker.service
# add's docker official ppa package source for Docker engine and install it
# does not include docker-compose or docker-machine
# run as root
# ensure we have tools to install
apt-get -y install \
apt-transport-https \
ca-certificates \
# add official package repo key
curl -fsSL | sudo apt-key add -
# add official package repo
# change stable on the last line to edge for beta-like monthly releases
# stable releases are quarterly
add-apt-repository \
"deb [arch=amd64] \
$(lsb_release -cs) \
# remove lxcfs, as we don't need it if we're doing docker
service lxcfs stop
apt-get remove -y -q lxc-common lxcfs lxd lxd-client
apt-get update -q
# install docker community (free) edition
apt-get -y install docker-ce
# install docker specific ver
# we allow held changes here in case we need to rerun, script will still work 2nd time
#apt-get install -y -q docker-ce=17.05.0* --allow-change-held-packages
# hold to that version
#apt-mark hold docker-ce
# remove hold later for upgrade
#apt-mark unhold docker-ce
# see what upgrade options exist
#apt-cache policy docker-ce
# edit dockerd startup to enable namespaces and ensure overlay2
# note namespace won't work in all scenerios, like --net=host,
# but its tighter security so it's recommended to try using first
# this now uses the daemon.json method rather that the old way of modifying systemd
printf '{ "userns-remap" : "default" , "storage-driver" : "overlay2" }' > /etc/docker/daemon.json
systemctl restart docker.service
Copy link

tsabat commented Oct 24, 2016

here's the output from /var/log/syslog


Also, this results in a dollar-sign being added to the docker daemon args


Copy link

BretFisher commented Oct 28, 2016

Fixed the $ issue by replacing echo with printf. I can't replicate the "unauthenticated packages" error on 16.04 with AWS user-data @tsabat

Copy link

BretFisher commented Feb 7, 2018

Stole this from Tim for ad-hoc daemon options.

if [[ -f extra_daemon_args.json ]]; then
  # back up the original
  mv /etc/docker/daemon.json /etc/docker/daemon.json.bak
  # take the original daemon file and combine it with the extra_daemon_args file
  jq -s '.[0] * .[1]' /etc/docker/daemon.json.bak extra_daemon_args.json > /etc/docker/daemon.json

Copy link

hebronwatson commented Feb 7, 2018

Hey bud, thanks for this. you forgot to install software-properties-common and some may need python-software-properties as well
which results in a
add-apt-repository: command not found

thanks again! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment