查看: 1238|回复: 0

[评测分享] 【树莓派5 测评】 + 15.Docker功能测试(zmj)

[复制链接]
  • TA的每日心情
    奋斗
    昨天 10:11
  • 签到天数: 250 天

    连续签到: 1 天

    [LV.8]以坛为家I

    发表于 2024-4-30 16:48:52 | 显示全部楼层 |阅读模式
    分享到:
    本帖最后由 赵美京₁₉⁸⁸⁸ 于 2024-4-30 16:50 编辑

    【树莓派5 测评】 + 15.Docker功能测试(zmj)
    Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的 Linux或Windows操作系统的机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。
    1.        Docker安装

    Docker安装有多种方式,此处仅举例两种,且推荐第二种。
    1.1        安装方式1
    常规安装:
    1. //------安装指令
    2. # 更新本地软件包列表
    3. sudo apt update
    4. # 更新已安装的包
    5. sudo apt upgrade -y
    6. # 安装依赖包
    7. sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
    8. # 添加 Docker 官方 GPG 密钥
    9. sudo install -m 0755 -d /etc/apt/keyrings
    10. sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
    11. sudo chmod a+r /etc/apt/keyrings/docker.asc
    12. # 将存储库添加到 Apt 源
    13. echo \
    14.   "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
    15.   $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
    16.   sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    17. # 再次更新本地软件包列表,更新完成后可以使用 apt-cache madison docker-ce | awk '{ print $3 }' 列出存储库中可用版本
    18. sudo apt update
    19. # 安装 Docker
    20. sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
    21. # 验证安装
    22. docker --version
    23. docker compose version
    24. # 启动 docker 守护进程,同时设置开机启动(这部分操作在虚拟机中无法使用,需要手动启动 docker)
    25. sudo systemctl start docker
    26. sudo systemctl enable docker
    27. 或者
    28. sudo systemctl enable --now docker
    复制代码
    1.2        安装方式2
    便捷安装,安装的是最新版。
    1. //------安装指令
    2. # 便捷安装
    3. curl -fsSL https://get.docker.com/ | sh
    4. # 验证安装
    5. docker --version
    6. docker compose version
    7. # 启动 docker 守护进程,同时设置开机启动(这部分操作在虚拟机中无法使用,需要手动启动 docker)
    8. sudo systemctl start docker
    9. sudo systemctl enable docker
    10. 或者
    11. sudo systemctl enable --now docker
    12. //------Log信息
    13. zhaomeijing@raspberrypi5:~/workspace/15_docker$ ll
    14. total 8
    15. drwxr-xr-x  2 zhaomeijing zhaomeijing 4096 Apr 28 15:05 ./
    16. drwxr-xr-x 16 zhaomeijing zhaomeijing 4096 Apr 28 15:05 ../
    17. zhaomeijing@raspberrypi5:~/workspace/15_docker$ curl -fsSL https://get.docker.com/ | sh
    18. # Executing docker install script, commit: e5543d473431b782227f8908005543bb4389b8de
    19. + sudo -E sh -c apt-get update -qq >/dev/null
    20. + sudo -E sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq apt-transport-https ca-certificates curl >/dev/null
    21. + sudo -E sh -c install -m 0755 -d /etc/apt/keyrings
    22. + sudo -E sh -c curl -fsSL "https://download.docker.com/linux/debian/gpg" | gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg
    23. + sudo -E sh -c chmod a+r /etc/apt/keyrings/docker.gpg
    24. + sudo -E sh -c echo "deb [arch=arm64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian bookworm stable" > /etc/apt/sources.list.d/docker.list
    25. + sudo -E sh -c apt-get update -qq >/dev/null
    26. + sudo -E sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-ce-rootless-extras docker-buildx-plugin >/dev/null
    27. + sudo -E sh -c docker version
    28. Client: Docker Engine - Community
    29. Version:           26.1.0
    30. API version:       1.45
    31. Go version:        go1.21.9
    32. Git commit:        9714adc
    33. Built:             Mon Apr 22 17:06:59 2024
    34. OS/Arch:           linux/arm64
    35. Context:           default

    36. Server: Docker Engine - Community
    37. Engine:
    38.   Version:          26.1.0
    39.   API version:      1.45 (minimum version 1.24)
    40.   Go version:       go1.21.9
    41.   Git commit:       c8af8eb
    42.   Built:            Mon Apr 22 17:06:59 2024
    43.   OS/Arch:          linux/arm64
    44.   Experimental:     false
    45. containerd:
    46.   Version:          1.6.31
    47.   GitCommit:        e377cd56a71523140ca6ae87e30244719194a521
    48. runc:
    49.   Version:          1.1.12
    50.   GitCommit:        v1.1.12-0-g51d5e94
    51. docker-init:
    52.   Version:          0.19.0
    53.   GitCommit:        de40ad0

    54. ================================================================================

    55. To run Docker as a non-privileged user, consider setting up the
    56. Docker daemon in rootless mode for your user:

    57.     dockerd-rootless-setuptool.sh install

    58. Visit https://docs.docker.com/go/rootless/ to learn about rootless mode.


    59. To run the Docker daemon as a fully privileged service, but granting non-root
    60. users access, refer to https://docs.docker.com/go/daemon-access/

    61. WARNING: Access to the remote API on a privileged Docker daemon is equivalent
    62.          to root access on the host. Refer to the 'Docker daemon attack surface'
    63.          documentation for details: https://docs.docker.com/go/attack-surface/

    64. ================================================================================

    65. zhaomeijing@raspberrypi5:~/workspace/15_docker$
    复制代码
    //------Docker便捷安装:
    image-20240429114020026.png
    2.        Docker测试
    Docker测试流程:
            首先查看Docker版本,然后运行“hello-world”测试,最后删除Docker镜像。
    测试指令如下:
    1. //------测试指令
    2. //---版本查看
    3. docker --version
    4. docker compose version
    5. //---运行状态(无镜像)
    6. sudo docker images
    7. sudo docker ps -a
    8. //---测试运行hello-world
    9. sudo docker run hello-world
    10. //---运行状态(有镜像)
    11. sudo docker images
    12. //---先删除Docker容器,再删除Docker镜像
    13. sudo docker ps -a
    14. sudo docker rm ff5d40552233
    15. sudo docker images
    16. sudo docker rmi ee301c921b8a
    17. //------Log信息
    18. zhaomeijing@raspberrypi5:~/workspace/15_docker$ docker --version
    19. Docker version 26.1.0, build 9714adc
    20. zhaomeijing@raspberrypi5:~/workspace/15_docker$ docker compose version
    21. Docker Compose version v2.26.1
    22. zhaomeijing@raspberrypi5:~/workspace/15_docker$ sudo docker images
    23. REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
    24. zhaomeijing@raspberrypi5:~/workspace/15_docker$ sudo docker ps -a
    25. CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
    26. zhaomeijing@raspberrypi5:~/workspace/15_docker$ sudo docker run hello-world
    27. Unable to find image 'hello-world:latest' locally
    28. latest: Pulling from library/hello-world
    29. 478afc919002: Pull complete
    30. Digest: sha256:a26bff933ddc26d5cdf7faa98b4ae1e3ec20c4985e6f87ac0973052224d24302
    31. Status: Downloaded newer image for hello-world:latest

    32. Hello from Docker!
    33. This message shows that your installation appears to be working correctly.

    34. To generate this message, Docker took the following steps:
    35. 1. The Docker client contacted the Docker daemon.
    36. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    37.     (arm64v8)
    38. 3. The Docker daemon created a new container from that image which runs the
    39.     executable that produces the output you are currently reading.
    40. 4. The Docker daemon streamed that output to the Docker client, which sent it
    41.     to your terminal.

    42. To try something more ambitious, you can run an Ubuntu container with:
    43. $ docker run -it ubuntu bash

    44. Share images, automate workflows, and more with a free Docker ID:
    45. https://hub.docker.com/

    46. For more examples and ideas, visit:
    47. https://docs.docker.com/get-started/

    48. zhaomeijing@raspberrypi5:~/workspace/15_docker$ sudo docker images
    49. REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
    50. hello-world   latest    ee301c921b8a   12 months ago   9.14kB
    51. zhaomeijing@raspberrypi5:~/workspace/15_docker$ sudo docker ps -a
    52. CONTAINER ID   IMAGE         COMMAND    CREATED          STATUS                      PORTS     NAMES
    53. ff5d40552233   hello-world   "/hello"   15 seconds ago   Exited (0) 13 seconds ago             compassionate_noyce
    54. zhaomeijing@raspberrypi5:~/workspace/15_docker$ sudo docker rmi ee301c921b8a
    55. Error response from daemon: conflict: unable to delete ee301c921b8a (must be forced) - image is being used by stopped container ff5d40552233
    56. zhaomeijing@raspberrypi5:~/workspace/15_docker$ sudo docker ps -a
    57. CONTAINER ID   IMAGE         COMMAND    CREATED       STATUS                   PORTS     NAMES
    58. ff5d40552233   hello-world   "/hello"   4 hours ago   Exited (0) 4 hours ago             compassionate_noyce
    59. zhaomeijing@raspberrypi5:~/workspace/15_docker$ sudo docker rm ff5d40552233
    60. ff5d40552233
    61. zhaomeijing@raspberrypi5:~/workspace/15_docker$ sudo docker images
    62. REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
    63. hello-world   latest    ee301c921b8a   12 months ago   9.14kB
    64. zhaomeijing@raspberrypi5:~/workspace/15_docker$ sudo docker rmi ee301c921b8a
    65. Untagged: hello-world:latest
    66. Untagged: hello-world@sha256:a26bff933ddc26d5cdf7faa98b4ae1e3ec20c4985e6f87ac0973052224d24302
    67. Deleted: sha256:ee301c921b8aadc002973b2e0c3da17d701dcd994b606769a7e6eaa100b81d44
    68. Deleted: sha256:12660636fe55438cc3ae7424da7ac56e845cdb52493ff9cf949c47a7f57f8b43
    69. zhaomeijing@raspberrypi5:~/workspace/15_docker$ sudo docker images
    70. REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
    71. zhaomeijing@raspberrypi5:~/workspace/15_docker$
    复制代码
    //------Docker测试结果:
    image-20240429180249722.png
    3.        其他Docker指令
    下面列出一些相对常用的Docker指令,更多指令请参考Docker帮助指令“docker -h”。
    1. //------其他Docker指令
    2. //---基础配置
    3. # 开机自启动docker
    4. sudo systemctl enable docker
    5. # 启动docker
    6. sudo systemctl start docker
    7. # 查看docker运行状态
    8. sudo systemctl status docker
    9. //---建立Docker用户组
    10. 默认情况下,docker 命令会使用 Unix socket 与 Docker 引擎通讯。而只有 root 用户和 docker 组的用户才可以访问 Docker 引擎的 Unix socket。出于安全考虑,一般 Linux 系统上不会直接使用 root 用户。因此,更好地做法是将需要使用 docker 的用户加入 docker 用户组。
    11. # 建立 docker 组:
    12. sudo groupadd docker
    13. # 将当前用户加入 docker 组:
    14. sudo usermod -aG docker $USER
    15. # 重启docker
    16. sudo service docker restart
    17. # 切换当前会话到新 group
    18. newgrp - docker
    19. //---镜像与容器操作
    20. # 列出镜像
    21. docker image ls
    22. # 删除本地镜像
    23. docker image rm [选项] <镜像1> [<镜像2> ...]
    24. # 列出正在运行的容器
    25. docker ps
    26. docker container ls
    27. # 列出所有容器
    28. docker ps -a
    29. docker container ls -a
    30. # 删除容器
    31. docker container rm [选项] <容器1> [<容器2> ...]
    32. # 清理掉所有处于终止状态的容器
    33. docker container prune
    34. # 终止容器
    35. docker container stop [选项] <容器1> [<容器2> ...]
    36. # 启动容器
    37. docker container start [选项] <容器1> [<容器2> ...]
    38. # 重启容器
    39. docker container restart [选项] <容器1> [<容器2> ...]
    40. # 容器与本地文件传输
    41. docker cp 本地文件路径 容器ID:容器路径
    42. docker cp 容器ID:容器文件路径 本地路径
    复制代码

    //------end



    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-11-21 23:26 , Processed in 0.135156 second(s), 19 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.