How to install Docker and Docker Compose
1. Install Docker form Offical Repository
$ uname -a
Update Local Database
==> On Ubuntu $ sudo apt-get update ==> On CentOS 7 $ sudo yum check-update
==> On Ubuntu You’ll need to run these commands to allow your operating system to access the Docker repositories over HTTPS. $ sudo apt-get install apt-transport-https ca-certificates curl software-properties-common ==> On CentOS 7 $ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
Notes:
- apt-transport-https: Allows the package manager to transfer files and data over https
- ca-certificates: Allows the system (and web browser) to check security certificates
- curl: This is a tool for transferring data
- software-properties-common: Adds scripts for managing software
- The –y switch indicates to the yum installer to answer “yes” to any prompts that may come up. The yum-utils switch adds the yum-config-manager. Docker uses a device mapper storage driver, and the device-mapper-persistent-data and lvm2 packages are required for it to run correctly.
The GPG key is a security feature. This key is required to ensure
that all data is encrypted when downloading the necessary packages for
Docker:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
==> On Ubuntu Add the Docker repository for Ubuntu to the software source: $ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" Update the repositories you just added: $ sudo apt-get update ==> On CentOS 7 $ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Notes:
-
The command
$(lsb_release –cs)
scans and returns the codename of your Ubuntu installation – in this case, Bionic. Also, the final word of the command –stable
– is the type of Docker release. - A stable release is tested and confirmed to work, but updates are released less frequently.
==> On Ubuntu $ sudo apt-get install docker-ce ==> On CentOS 7 $ sudo yum install docker
==> On Ubuntu List the available versions of Docker: $ apt-cache madison docker-ce Install Specific Version of Docker: $ sudo apt-get install docker-ce=[version] Example: $ sudo apt-get install docker-ce=18.03.1~ce~3-0~ubuntu ==> On CentOS 7 List the available versions of Docker: $ yum list docker-ce --showduplicates | sort –r Install the selected Docker version: $ sudo yum install docker-ce-[VERSION STRING] Example: $ sudo yum install docker-ce-17.12.1.ce
==> On Ubuntu $ sudo apt install docker-compose ==> On CentOS 7 $ curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose $ chmod +x /usr/local/bin/docker-compose $ ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose Check Docker Compose version: $ docker-compose --version
$ sudo systemctl status docker
By default, the docker command can only be run by the root user or by
users in the docker group, which is automatically created during the
Docker installation. If you don't want to type sudo whenever you
run a docker command, add your username to the docker group:
$ sudo usermod -aG docker ${USER} $ su - ${USER} Enter the password to continue. Confirm your username have been added to the docker group: $ id -nG
Check Docker version
$ docker version
$ docker info
2. Remove Docker on Ubuntu
$ sudo apt --purge autoremove docker docker-engine docker.io containerd runc