Podman使用(Mac M1)

1. 前言

弃用docker选择使用podman的理由:

  1. 使用虚拟机进行容器管理
  2. 不需要本机root权限
  3. 非守护进程
  4. podman命令与docker一致

2. 安装及配置

使用homebrew安装podman

brew install podman
brew install podman-compose
brew install podman-desktop

创建podman虚拟机:通过podman-desktop创建

命令行创建:podman machine init

通过podman machine info查看虚拟机状态,这里的虚拟机是由qemu模拟的

通过podman machine ssh进入虚拟机配置国内镜像源

vi /etc/containers/registries.conf

配置内容如下:

unqualified-search-registries = ["docker.io"]

[[registry]]
prefix = "docker.io"
location = "docker.io"

[[registry.mirror]]
location = "hub-mirror.c.163.com"

[[registry.mirror]]
location = "mirror.baidubce.com"

[[registry.mirror]]
location = "ustc-edu-cn.mirror.aliyuncs.com"

[[registry.mirror]]
location = "registry.docker-cn.com"

通过podman info | grep registries -A 25查看是否配置成功

3. 环境搭建

因为是用M1 Mac去使用,所以在环境搭建的时候需要看所需镜像是否支持arm架构。

这里搭一个之前出过的题,项目地址如下:

https://github.com/seizer-zyx/second-xupt-ctf.git

Dockerfile内容如下:

FROM ubuntu:20.04

RUN sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
RUN apt update
RUN apt install -y python3
RUN apt install -y python3-pip
RUN pip3 install flask -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN mkdir /app

WORKDIR /app

COPY app /app
COPY flag /

ENTRYPOINT python3 /app/app.py

EXPOSE 80

去Dockerhub上看下,可知是支持的

通过podman build .构建镜像,构建完成,通过podman images查看

忘记给名称了,构建过程中通过-t参数给新构建的镜像予以名称podman build . -t flask

已经构建的镜像也可以予以名称podman tag c860 flask

接下来通过镜像启动容器podman run -it -d -P flask

容器启动成功,访问一下

posted @ 2024-02-02 14:15  seizer-zyx  阅读(440)  评论(0编辑  收藏  举报