debian 7 -- wheezy
debian 8 -- jessie
debian 9 -- stretch
Uninstall old versions
安装过的话,先移除旧的软件
$ sudo apt-get remove docker docker-engine docker.io
SET UP THE REPOSITORY
-
更新仓库信息:
$ sudo apt-get update
-
安装软件包:
3. 添加官方GPG key:
$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
通过搜索后8位验证密钥:
$ sudo apt-key fingerprint 0EBFCD88 pub 4096R/0EBFCD88 2017-02-22 Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 uid Docker Release (CE deb) <docker@docker.com> sub 4096R/F273FCD8 2017-02-22
4. 设置库
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
INSTALL DOCKER CE
Note: This procedure works for Debian on
x86_64
/amd64
, Debian ARM, or Raspbian.
-
更新软件仓库:
$ sudo apt-get update
-
安装最新版Docker CE:
$ sudo apt-get install docker-ce
我在这一步提示,E: Unable to locate package docer-ce
搜了下资料执行了如下后,可以正常安装,具体原因不详,赶着下班能安装成功就万事大吉 - . - :
echo "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee -a /etc/apt/sources.list.d/docker.list
sudo apt-get update
sudo apt-cache policy docker-ce
提示如下:
docker-ce: Installed: (none) Candidate: 18.03.0~ce-0~debian Version table: 18.03.0~ce-0~debian 500 500 https://download.docker.com/linux/debian stretch/stable amd64 Packages 17.12.1~ce-0~debian 500 500 https://download.docker.com/linux/debian stretch/stable amd64 Packages 17.12.0~ce-0~debian 500 500 https://download.docker.com/linux/debian stretch/stable amd64 Packages 17.09.1~ce-0~debian 500 500 https://download.docker.com/linux/debian stretch/stable amd64 Packages 17.09.0~ce-0~debian 500 500 https://download.docker.com/linux/debian stretch/stable amd64 Packages 17.06.2~ce-0~debian 500 500 https://download.docker.com/linux/debian stretch/stable amd64 Packages 17.06.1~ce-0~debian 500 500 https://download.docker.com/linux/debian stretch/stable amd64 Packages 17.06.0~ce-0~debian 500 500 https://download.docker.com/linux/debian stretch/stable amd64 Packages 17.03.2~ce-0~debian-stretch 500 500 https://download.docker.com/linux/debian stretch/stable amd64 Packages 17.03.1~ce-0~debian-stretch 500 500 https://download.docker.com/linux/debian stretch/stable amd64 Packages 17.03.0~ce-0~debian-stretch 500 500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
接着安装docker-ce:
sudo apt-get install docker-ce
-
在生产环境你需要安装一个特定版本的Docker CE而非总是最新的. 这个输出截断可以列出可用的版本:
$ apt-cache madison docker-ce docker-ce | 17.12.0~ce-0~debian | https://download.docker.com/linux/debian jessie/stable amd64 Packages
The contents of the list depend upon which repositories are enabled. Choose a specific version to install. The second column is the version string. The third column is the repository name, which indicates which repository the package is from and by extension its stability level. To install a specific version, append the version string to the package name and separate them by an equals sign (
=
):$ sudo apt-get install docker-ce=<VERSION_STRING>
The Docker daemon starts automatically.
-
通过运行
hello-world
镜像来验证Docker CE安装成功.x86_64:
$ sudo docker run hello-world
armhf:
$ sudo docker run armhf/hello-world
This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.
Docker CE is installed and running. The docker
group is created but no users are added to it. You need to use sudo
to run Docker commands. Continue to Linux postinstall to allow non-privileged users to run Docker commands and for other optional configuration steps. For Raspbian, you can optionally install Docker Compose for Raspbian.
非root权限使用docker
sudo groupadd docker //创建docker组 sudo gpasswd -a ${USER} docker //将当前用户加入docker组 sudo systemctl restart docker //重新启动docker服务 当前用户退出系统重新登陆 docker ps //运行docker命令
UPGRADE DOCKER CE
To upgrade Docker CE, first run sudo apt-get update
, then follow the installation instructions, choosing the new version you want to install.
Install from a package
如果你不能使用Docker仓库来安装Docker CE, 你可以下载相应发行版的 .deb
文件并手动安装。 你每次想要更新Docker的时候都需要下载一个新的文件.
-
Go to
https://download.docker.com/linux/debian/dists/
, choose your Debian version, browse topool/stable/
, choose eitheramd64
orarmhf
, and download the.deb
file for the Docker CE version you want to install.Note: To install an edge package, change the word
stable
in the URL toedge
. Learn about stable and edgechannels. -
Install Docker CE, changing the path below to the path where you downloaded the Docker package.
$ sudo dpkg -i /path/to/package.deb
The Docker daemon starts automatically.
-
Verify that Docker CE is installed correctly by running the
hello-world
image.$ sudo docker run hello-world
This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.
Docker CE is installed and running. The docker
group is created but no users are added to it. You need to use sudo
to run Docker commands. Continue to Post-installation steps for Linux to allow non-privileged users to run Docker commands and for other optional configuration steps. For Raspbian, you can optionally install Docker Compose for Raspbian.
UPGRADE DOCKER CE
To upgrade Docker, download the newer package file and repeat the installation procedure, pointing to the new file.
Install using the convenience script
Docker provides convenience scripts at get.docker.com and test.docker.com for installing edge and testing versions of Docker CE into development environments quickly and non-interactively. The source code for the scripts is in the docker-install
repository. Using these scripts is not recommended for production environments, and you should understand the potential risks before you use them:
- The scripts require
root
orsudo
privileges to run. Therefore, you should carefully examine and audit the scripts before running them. - The scripts attempt to detect your Linux distribution and version and configure your package management system for you. In addition, the scripts do not allow you to customize any installation parameters. This may lead to an unsupported configuration, either from Docker’s point of view or from your own organization’s guidelines and standards.
- The scripts install all dependencies and recommendations of the package manager without asking for confirmation. This may install a large number of packages, depending on the current configuration of your host machine.
- The script does not provide options to specify which version of Docker to install, and installs the latest version that is released in the “edge” channel.
- Do not use the convenience script if Docker has already been installed on the host machine using another mechanism.
This example uses the script at get.docker.com to install the latest release of Docker CE on Linux. To install the latest testing version, use test.docker.com instead. In each of the commands below, replace each occurrence of get
with test
.
Warning:
Always examine scripts downloaded from the internet before running them locally.
$ curl -fsSL get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
<output truncated>
If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:
sudo usermod -aG docker your-user
Remember to log out and back in for this to take effect!
WARNING: Adding a user to the "docker" group grants the ability to run
containers which can be used to obtain root privileges on the
docker host.
Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
for more information.
Docker CE is installed. It starts automatically on DEB
-based distributions. On RPM
-based distributions, you need to start it manually using the appropriate systemctl
or service
command. As the message indicates, non-root users can’t run Docker commands by default.
UPGRADE DOCKER AFTER USING THE CONVENIENCE SCRIPT
If you installed Docker using the convenience script, you should upgrade Docker using your package manager directly. There is no advantage to re-running the convenience script, and it can cause issues if it attempts to re-add repositories which have already been added to the host machine.
Install Docker Compose for Raspbian
You can install Docker Compose using pip
:
$ sudo pip install docker-compose
Hypriot provides a static binary of docker-compose
for Raspbian. It may not always be up to date, but if space is at a premium, you may find it useful. To use it, first follow Hypriot’s instructions for setting up the repository, then run the following command:
sudo apt-get install docker-compose
Uninstall Docker CE
-
Uninstall the Docker CE package:
$ sudo apt-get purge docker-ce
-
Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:
$ sudo rm -rf /var/lib/docker