1、Update the apt package index:
sudo apt-get update
2、Install packages to allow apt to use a repository over HTTPS:
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
3、 Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
4、Use the following command to set up the stable repository.
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
1、Update the apt package index.
sudo apt-get update
2、 Install the latest version of Docker CE, or go to the next step to install a specific version:
sudo apt-get install docker-ce
3、Verify that Docker CE is installed correctly by running the hello-world image.
sudo docker run hello-world
1、Create the docker group.
sudo groupadd docker
2、Add your user to the docker group.
sudo usermod -aG docker $USER
1、Run this command to download the latest version of Docker Compose:
sudo curl -L https://github.com/docker/compose/releases/download/1.20.1/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
2、Apply executable permissions to the binary:
sudo chmod +x /usr/local/bin/docker-compose
3、Test the installation.
docker-compose --version
如果安装过程中遇到这个问题:curl: (7) Failed to connect to github-production-release-asset-2e65be.s3.amazonaws.com port 443: Connection timed out.
问题原因:该地址(github-production-release-asset-2e65be.s3.amazonaws.com) 需要的一些下载的访问被国内屏蔽了,需要修改hosts文件,使用香港的服务器。
解决办法如下:
sudo gedit /etc/hosts
,添加219.76.4.4 github-cloud.s3.amazonaws.comsudo /etc/init.d/networking restart
hosts是一个没有扩展名的系统文件,其作用就是将一些常用的网址域名与其对应的IP地址建立一个关联“数据库”,当用户在浏览器中输入一个需要登录的网址时,系统会首先自动从hosts文件中寻找对应的IP地址,一旦找到,系统会立即打开对应网页,如果没有找到,则系统会再将网址提交DNS域名解析服务器进行IP地址的解析。
操作系统规定,在进行DNS请求以前,先检查系自己的hosts文件中是否有这个域名和IP的映射关系。如果有,则直接访问这个IP地址指定的网络位置,如果没有,再向已知的DNS服务器提出域名解析请求。也就是说hosts的IP解析优先级比DNS要高。更准确一些是:dns缓存 > hosts > dns服务。
参考文档:
[1]. Get Docker CE for Ubuntu
[2]. Install Docker Compose
[3]. 安装docker-compose异常: Failed to connect to github-production-release-XX-
[4]. Linux hosts文件详解及配置