根据官方文档,树莓派系统RaspberryPi OS是不支持通过添加软 件源的方式直接安装的。必须通过官方提供的get-docker.sh脚本来安装。幸好脚本里以及添加了中国区可用的镜像选项,不用自己去修改脚本本身。
case "$mirror" in
Aliyun)
DOWNLOAD_URL="https://mirrors.aliyun.com/docker-ce"
;;
AzureChinaCloud)
DOWNLOAD_URL="https://mirror.azure.cn/docker-ce"
;;
esac
# apt-get remove docker docker-engine docker.io containerd runc
$ curl -fsSL https://get.docker.com -o get-docker.sh
# sh get-docker.sh --mirror Aliyun
安装完成后应该会显示类似如下输出信息:
# Executing docker install script, commit: 26ff363bcf3b3f5a00498ac43694bf1c7d9ce16c
+ sh -c apt-get update -qq >/dev/null
+ sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq apt-transport-https ca-certificates curl >/dev/null
+ sh -c curl -fsSL "https://mirrors.aliyun.com/docker-ce/linux/raspbian/gpg" | apt-key add -qq - >/dev/null
Warning: apt-key output should not be parsed (stdout is not a terminal)
+ sh -c echo "deb [arch=armhf] https://mirrors.aliyun.com/docker-ce/linux/raspbian buster stable" > /etc/apt/sources.list.d/docker.list
+ sh -c apt-get update -qq >/dev/null
+ [ -n ]
+ sh -c apt-get install -y -qq --no-install-recommends docker-ce >/dev/null
+ sh -c docker version
Client: Docker Engine - Community
Version: 19.03.13
API version: 1.40
Go version: go1.13.15
Git commit: 4484c46
Built: Wed Sep 16 17:07:02 2020
OS/Arch: linux/arm
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.13
API version: 1.40 (minimum version 1.12)
Go version: go1.13.15
Git commit: 4484c46
Built: Wed Sep 16 17:00:52 2020
OS/Arch: linux/arm
Experimental: false
containerd:
Version: 1.3.7
GitCommit: 8fba4e9a7d01810a393d5d25a3621dc101981175
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
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 that you will have to log out and back in for this to take effect!
WARNING: Adding a user to the "docker" group will grant 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分组下,并重新登录。
按照默认的安装方式,Docker相关的镜像、容器等文件会保存在/var/lib/docker和/var/lib/containerd目录下。
$ docker run hello-world
如果安装正确,就会产生如下输出:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
4ee5c797bcd7: Pull complete
Digest: sha256:8c5aeeb6a5f3ba4883347d3747a7249f491766ca1caa47e5da5dfcf6b9b717c0
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(arm32v7)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
# systemctl enable docker
如果需要禁用自启动,执行systemctl disable docker即可。
Docker客户端版本大于1.10.0的用户可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速通道。
# mkdir -p /etc/docker
# tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["YOUR_REGISTRY_MIRROR_ADDRESS"],
"insecure-registries": []
}
EOF
# systemctl daemon-reload
# systemctl restart docker
由于Docker默认会在访问镜像仓库时使用HTTPS安全连接,如果本地部署了未采用HTTPS的私有仓库,则需要把仓库地址配置在这里,否则请求会失败。
由于是在Linux下,Docker-Compose不会随Docker一起安装,还需要手动安装。但是Github上的官方linux平台镜像只提供x84和x64两个版本,根本没有arm
架构的选项。而根据官方文档尝试过将Docker-Compose作为一个
Docker容器来安装运行的方式后发现一直报错:standard_init_linux.go:211: exec user process caused "no such file or directory",
最后只能使用pip安装的方式。
# apt update
# apt install -y python3-pip libffi-dev
# pip3 install docker-compose
安装完成后就可以开始使用docker-compose命令了。
由于官方Docker Hub有各种各样的限制,即使用了第三方镜像加速,仍然不适合日常开发使用。为了在团队内部快速进行开发、测试、持续集成与持续交付,内部必 须搭建一个开发、测试用的镜像库。而Docker提供了一个开源的解决方案:Docker Registry。Docker Registry的特点是非常容易上手,一行命令就可以完成 部署,这也是大多数Docker应用的特点。同时Docker Registry也预留了很多可配置的选项,以供在要求严格的实际生产环境下使用。
如果不需要用户身份认证,一行命令就可以完成Docker Registry的下载和部署。这个实例运行在一个叫registry的容器内,且会跟随系统自动启动。
$ docker run -d -p 5000:5000 --restart=always --name registry registry:2
如果想停止运行Docker Registry,只需要以下命令:
$ docker container stop registry
如果想移除Docker Registry服务及数据,只需要以下命令:
$ docker container stop registry && docker container rm -v registry
下载镜像并推送到本地Docker Registry:
$ docker pull ubuntu
$ docker image tag ubuntu localhost:5000/ubuntu
$ docker push localhost:5000/ubuntu
从本地Docker Registry下载镜像:
$ docker pull localhost:5000/ubuntu
更多关于Docker Registry配置的详细信息见官方文档: