翼度科技»论坛 云主机 LINUX 查看内容

容器平台

9

主题

9

帖子

27

积分

新手上路

Rank: 1

积分
27
Podman
(01)Install Podman
Podman:安装
  安装容器管理工具的Podman。
[1]  安装 Podman。
  1. root@dlp:~# apt -y install podman
复制代码
 
[2]  下载官方镜像并创建一个容器,并在容器内输出 [Welcome to the Podman World] 字样。
  1. # download the official image
  2. root@dlp:~# podman pull ubuntu
  3. # run echo inside a container
  4. root@dlp:~# podman run ubuntu /bin/echo "Welcome to the Podman World"
  5. Welcome to the Podman World
  6. Resolved "ubuntu" as an alias (/etc/containers/registries.conf.d/shortnames.conf)
  7. Trying to pull docker.io/library/ubuntu:latest...
  8. Getting image source signatures
  9. Copying blob 49b384cc7b4a done   |
  10. Copying config bf3dc08bfe done   |
  11. Writing manifest to image destination
  12. bf3dc08bfed031182827888bb15977e316ad797ee2ccb63b4c7a57fdfe7eb31d
复制代码
 
[3]  使用 和 [t] 选项连接到容器的交互式会话,如下所示。
  如果 [exit] 退出容器会话,则容器的过程完成。
  1. root@dlp:~# podman run -it ubuntu /bin/bash
  2. root@591e1ea31c34:/#     # connected
  3. root@591e1ea31c34:/# uname -a
  4. Linux 591e1ea31c34 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
  5. root@591e1ea31c34:/# exit
  6. exit
  7. root@dlp:~#     # come back
复制代码
 
[4]  如果要将容器作为守护进程运行,请添加 [d] 选项。
  1. root@dlp:~# podman run -itd ubuntu /bin/bash
  2. # show podman processes
  3. root@dlp:~# podman ps
  4. a45d9a04eb16c35c28bf2c223a41613a99c4eaddba7e619decbe27e851eb906b
  5. CONTAINER ID  IMAGE                            COMMAND     CREATED         STATUS         PORTS       NAMES
  6. a45d9a04eb16  docker.io/library/ubuntu:latest  /bin/bash   16 seconds ago  Up 16 seconds              angry_driscoll
  7. # attach to container session
  8. root@dlp:~# podman exec -it a45d9a04eb16 /bin/bash
  9. root@a45d9a04eb16:/#     # connected
  10. root@a45d9a04eb16:/# exit
  11. # stop container process
  12. # * if force stop, specify [podman kill ***]
  13. root@dlp:~# podman stop a45d9a04eb16
  14. root@dlp:~# podman ps
  15. CONTAINER ID  IMAGE   COMMAND  CREATED  STATUS  PORTS   NAMES
复制代码
 
(02)Add Container Images
Podman:添加容器镜像
  添加修改设置的新容器映像。
[1]  例如,使用安装 [apache2] 更新官方镜像,并将其添加为新的容器镜像。
  1. # show container images
  2. root@dlp:~# podman images
  3. REPOSITORY                TAG         IMAGE ID      CREATED     SIZE
  4. docker.io/library/ubuntu  latest      bf3dc08bfed0  5 days ago  78.7 MB
  5. # run a container and install [apache2]
  6. root@dlp:~# podman run ubuntu /bin/bash -c "apt-get update; apt-get -y install apache2"
  7. root@dlp:~# podman ps -a | tail -1
  8. # add the image that [apache2] was installed
  9. root@dlp:~# podman commit 8ba738311a1b srv.world/ubuntu-apache2
  10. # show container images
  11. root@dlp:~# podman images
  12. # confirm [apache2] to run a container
  13. root@dlp:~# podman run srv.world/ubuntu-apache2 /usr/bin/whereis apache2
  14. apache2: /usr/sbin/apache2 /usr/lib/apache2 /etc/apache2 /usr/share/apache2
  15. 8ba738311a1b  docker.io/library/ubuntu:latest  /bin/bash -c apt-...  26 seconds ago  Exited (0) 8 seconds ago              intelligent_haibt
  16. Getting image source signatures
  17. Copying blob 80098e3d304c skipped: already exists
  18. Copying blob 8b942a48c2d6 done   |
  19. Copying config 38d5083368 done   |
  20. Writing manifest to image destination
  21. 38d5083368637cec96e051ebe22f2b5776538eb9ad7dc2143f4d617896ec05f4
  22. REPOSITORY                TAG         IMAGE ID      CREATED         SIZE
  23. srv.world/ubuntu-apache2  latest      38d508336863  26 seconds ago  226 MB
  24. docker.io/library/ubuntu  latest      bf3dc08bfed0  5 days ago      78.7 MB
复制代码
 
(03)容器服务接入
Podman:访问容器上的服务
  如果要访问在容器上作为守护程序运行的 HTTP 或 SSH 等服务,请按如下方式进行配置。
[1]  例如,使用已安装 [apache2] 的容器。
  1. root@dlp:~# podman images
  2. # run a container and also start [apache2]
  3. # map with [-p xxx:xxx] to [(Host Port):(Container Port)]
  4. root@dlp:~# podman run -dt -p 8081:80 --security-opt apparmor=unconfined srv.world/ubuntu-apache2 /usr/sbin/apachectl -D FOREGROUND
  5. root@dlp:~# podman ps
  6. REPOSITORY                TAG         IMAGE ID      CREATED             SIZE
  7. srv.world/ubuntu-apache2  latest      38d508336863  About a minute ago  226 MB
  8. docker.io/library/ubuntu  latest      bf3dc08bfed0  5 days ago          78.7 MB
  9. 77c61575ad7b23c0091e0744cf691d8fb28484bd52a3be00280456e64309b191
  10. CONTAINER ID  IMAGE                            COMMAND               CREATED         STATUS         PORTS                 NAMES
  11. 77c61575ad7b  srv.world/ubuntu-apache2:latest  /usr/sbin/apachec...  14 seconds ago  Up 14 seconds  0.0.0.0:8081->80/tcp  affectionate_mirzakhani
  12. # create a test page
  13. root@dlp:~# podman exec 77c61575ad7b /bin/bash -c 'echo "Apache2 on Podman Container" > /var/www/html/index.html'
  14. # verify accesses
  15. root@dlp:~# curl localhost:8081
  16. Apache2 on Podman Container
  17. # also possible to access via container network
  18. root@dlp:~# podman inspect -l | grep "IPAddress
  19. root@dlp:~# curl 10.88.0.7
  20. Apache2 on Podman Container
  21.             "IPAddress": "10.88.0.7",
  22.                     "IPAddress": "10.88.0.7",
复制代码
 
(04)使用Dockerfile
Podman:使用Dockerfile
  使用Dockerfile并自动创建容器映像。
  它对容器映像的配置管理也很有用。
[1]  例如,创建一个已安装并启动 Nginx 的 Dockerfile。
  1. root@dlp:~# vi Dockerfile
  2. # create new
  3. FROM ubuntu
  4. MAINTAINER ServerWorld <admin@srv.world>
  5. RUN apt-get update
  6. RUN apt-get -y install nginx
  7. RUN echo "Dockerfile Test on Nginx" > /var/www/html/index.html
  8. EXPOSE 80
  9. CMD ["/usr/sbin/nginx", "-g", "daemon off;"]
  10. # build image ⇒ podman build -t [image name]:[tag] .
  11. root@dlp:~# podman build -t srv.world/ubuntu-nginx:latest .
  12. root@dlp:~# podman images
  13. # run container
  14. root@dlp:~# podman run -d -p 80:80 --security-opt apparmor=unconfined srv.world/ubuntu-nginx
  15. root@dlp:~# podman ps
  16. STEP 1/7: FROM ubuntu
  17. STEP 2/7: MAINTAINER ServerWorld <admin@srv.world>
  18. --> f2fc42956ea5
  19. STEP 3/7: RUN apt-get update
  20. .....
  21. .....
  22. STEP 6/7: EXPOSE 80
  23. --> 79117f75b19a
  24. STEP 7/7: CMD ["/usr/sbin/nginx", "-g", "daemon off;"]
  25. COMMIT srv.world/ubuntu-nginx:latest
  26. --> 1b1a4d3f4f26
  27. Successfully tagged srv.world/ubuntu-nginx:latest
  28. 1b1a4d3f4f26fdac6a7556c81a8cee65bfdbaaeff204ccc700f16b91d83e8dec
  29. REPOSITORY                TAG         IMAGE ID      CREATED             SIZE
  30. srv.world/ubuntu-nginx    latest      1b1a4d3f4f26  About a minute ago  125 MB
  31. srv.world/ubuntu-apache2  latest      38d508336863  37 minutes ago      226 MB
  32. docker.io/library/ubuntu  latest      bf3dc08bfed0  5 days ago          78.7 MB
  33. 1628817a1fa315f96be582e324daf4fad31bc51f1ef015be6dd3f2d2750fb5fd
  34. CONTAINER ID  IMAGE                          COMMAND               CREATED         STATUS         PORTS               NAMES
  35. 1628817a1fa3  srv.world/ubuntu-nginx:latest  /usr/sbin/nginx -...  18 seconds ago  Up 18 seconds  0.0.0.0:80->80/tcp  intelligent_chatterjee
  36. # verify accesses
  37. root@dlp:~# curl localhost
  38. Dockerfile Test on Nginx
  39. # also possible to access via container network
  40. root@dlp:~# podman inspect -l | grep "IPAddress
  41. root@dlp:~# curl 10.88.0.2
  42. Dockerfile Test on Nginx
  43.             "IPAddress": "10.88.0.2",
  44.                     "IPAddress": "10.88.0.2",
复制代码
 
Dockerfile 的格式为 [INSTRUCTION arguments] 。
有关指令,请参阅以下说明。
指令描述
FROM它为后续指令设置基础映像。
MAINTAINER它设置生成图像的“作者”字段。
RUN它将在创建 Docker 映像时执行任何命令。
CMD它将在执行 Docker 容器时执行任何命令。
ENTRYPOINT它将在执行 Docker 容器时执行任何命令。
LABEL它将元数据添加到图像中。
EXPOSE它通知 Docker 容器将在运行时侦听指定的网络端口。
ENV它设置环境变量。
ADD它复制新文件、目录或远程文件 URL。
COPY它复制新文件或目录。
[ADD]的区别在于无法指定远程URL,也不会自动提取存档文件。
VOLUME它创建一个具有指定名称的挂载点,并将其标记为持有 从本机主机或其他容器外部挂载的卷。
USER它设置用户名或 UID。
WORKDIR它设置工作目录。
 
(05)使用外部存储
(06)使用外部存储(NFS)
(07)使用注册表
(08)Podman网络基础
(09)使用Docker CLI
(10)使用Docker Compose
(11)创建Pod
(12)普通用户使用
(13)生成Systemd单元文件
(14)容器资源使用情况
 

来源:https://www.cnblogs.com/nc086/p/18176668
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!
来自手机

举报 回复 使用道具