Skip to content

Instantly share code, notes, and snippets.

@mhnpd
Last active April 1, 2018 12:05
Show Gist options
  • Save mhnpd/bbed9a42ba7139fa9b5e76a903789d17 to your computer and use it in GitHub Desktop.
Save mhnpd/bbed9a42ba7139fa9b5e76a903789d17 to your computer and use it in GitHub Desktop.
# Docker setup in ubuntu and configuration in manually.
# Docker installation script is on my Docker-installation-withscript gist.
# First remove any older version or configuration of Docker in local machine. i.e. your targeted device.
sudo apt-get remove docker docker-engine docker-ce docker.io
sudo apt-get update
# Skip above steps if you have fresh install OS.
# Using repository method to install docker
sudo 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 -
# Verify that you now have the key with the fingerprint
# 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88,
# by searching for the last 8 characters of the fingerprint.
sudo apt-key fingerprint 0EBFCD88
# Use the following command to set up the stable repository. You always need the stable repository,
even if you want to install builds from the edge or test repositories as well. To add the edge
or test repository, add the word edge or test (or both) after the word stable in the commands below.
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
# Update you apt package
sudo apt-get update
# Install the latest version of Docker CE,
# or go to the next step to install a specific version.
# Any existing installation of Docker is replaced.
sudo apt-get install docker-ce
# Note : On production systems, you should install a specific version of Docker CE instead of
always using the latest. This output is truncated. List the available versions.
sudo apt-get install docker-ce=<VERSION>
# Verify that Docker CE is installed correctly by running the hello-world image.
sudo docker run hello-world
# If everything is okay docker should pull a hello-world image from its repo.
# If you want to change the setting to auto start docker service at startup/ disable auto start follow step below.
If you are in local machine you might want to disable auto start to avoide lagginess. Most current Linux distributions
(RHEL, CentOS, Fedora, Ubuntu 16.04 and higher) use systemd to manage which services start when the system boots.
Ubuntu 14.10 and below use upstart.
# Using systemd (Newer version od os.)
sudo systemctl enable docker
sudo systemctl disable docker
# upstart :(Older version ubuntu below 14). Docker is automatically configured to start on boot using upstart.
To disable this behavior, use the following command:
echo manual | sudo tee /etc/init/docker.override
sudo chkconfig docker on
# Docker on local machine might have a cache and image. If you want to clear the cache and everything use follwing command.
The first one cleans all dangling images. This is useful for removing intermediate images left over from multiple builds.
The second one is for removing stopped containers.
alias docker_clean_images='docker rmi $(docker images -a --filter=dangling=true -q)'
alias docker_clean_ps='docker rm $(docker ps --filter=status=exited --filter=status=created -q)'
# If you want to remove ALL of your cache, you first have to make sure all containers are stopped and removed, since you
cannot remove an image in use by a container.This would kill and remove all images in your cache. Less recommended, you
could wipe the /var/lib/docker dir and start docker over, but that’s hardly necessary just to clear the cache
sudo docker kill $(docker ps -q)
sudo docker_clean_ps
sudo docker rmi $(docker images -a -q)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment