Podman使用初体验

一、 背景

最近服务器空了下来想着玩玩最新的centos8所以将服务器升级了一波操作系统。刚好看到有替代docker的容器方案想着试试,故写此篇博客记录一下安装过程。

二、开始安装

对于linux操作不是很熟练的同学可以安装宝塔面板方便以后使用

curl -sSO http://download.bt.cn/install/install_panel.sh && bash install_panel.sh

安装podman

yum -y install podman

配置镜像加速

vim  /etc/containers/registries.conf

unqualified-search-registries = ["docker.io"]
[[registry]]
prefix = "docker.io"
location = "0duv5ifx.mirror.aliyuncs.com"

拉取镜像

[root@aliyun-node containers]# podman pull nginx
Completed short name "nginx" with unqualified-search registries (origin: /etc/containers/registries.conf)
Trying to pull docker.io/library/nginx:latest...
Getting image source signatures
Copying blob f72584a26f32 done  
Copying blob 0732ab25fa22 done  
Copying blob 7125e4df9063 done  
Copying blob d7f36f6fe38f done  
Copying blob a076a628af6f done  
Copying config f6d0b4767a done  
Writing manifest to image destination
Storing signatures
f6d0b4767a6c466c178bf718f99bea0d3742b26679081e52dbf8e0c7c4c42d74

index.html

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
     
     
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>hello podman!</h1>
</body>
</html>

nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

default.conf

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

}

启动容器

[root@aliyun-node containers]# podman images
REPOSITORY               TAG     IMAGE ID      CREATED      SIZE
docker.io/library/nginx  latest  f6d0b4767a6c  6 weeks ago  137 MB
[root@aliyun-node containers]# cd /home/
[root@aliyun-node home]# ls
[root@aliyun-node home]# mkdir nginx
[root@aliyun-node home]# ls
nginx
[root@aliyun-node home]# cd nginx
[root@aliyun-node nginx]# ls
[root@aliyun-node nginx]# 
[root@aliyun-node nginx]# mkdir html
[root@aliyun-node nginx]# mkdir log
[root@aliyun-node nginx]# mkdir html
mkdir: cannot create directory ‘html’: File exists
[root@aliyun-node nginx]# mkdir conf.d
[root@aliyun-node nginx]# mkdir conf
[root@aliyun-node nginx]# ls
conf  conf.d  html  log
[root@aliyun-node nginx]# 
[root@aliyun-node nginx]# podman run --name  nginx -d -p 80:80  -v  /home/nginx/log:/var/log/nginx   -v  /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf   -v  /home/nginx/conf.d:/etc/nginx/conf.d  -v /home/nginx/html:/usr/share/nginx/html  nginx
19f8570cad1b5ec0491420868e01d59f588f7b96a449023d29e68d19a9f896cc
[root@aliyun-node nginx]# podman ps
CONTAINER ID  IMAGE                           COMMAND               CREATED        STATUS            PORTS               NAMES
19f8570cad1b  docker.io/library/nginx:latest  nginx -g daemon o...  5 seconds ago  Up 4 seconds ago  0.0.0.0:80->80/tcp  nginx
[root@aliyun-node nginx]# 

在这里插入图片描述

docker命令使用习惯了的同学可以修改podman别名为docker即可,剩下的操作就和docker一样了。

echo "alias docker=podman" >> .bashrc
source .bashrc

Podman Compose

Podman Compose 等同于 Docker Compose,是用于固化容器运行参数以及协调容器之间的关系的一种较为简单的方案。

使用如下的命令,安装 Podman Compose,并根据自己的喜好设置别名(如果仍然忘不了 docker)

pip3 install podman-compose
echo "alias docker-compose=podman-compose" >> .bashrc
source .bashrc

如果以普通用户运行容器,此容器默认无法被外网访问,为了避免不必要的麻烦,建议以root用户创建并运行容器。

Guess you like

Origin blog.csdn.net/luomo0203/article/details/114025130