podman run -i -d -p 80:80 -v /data/:/data/ --privileged --name mytest centos:7.3.1611 /usr/sbin/init
-i: 允许你对容器进行交互
-d: 后台运行 不会进入容器
-p 端口号,左侧服务器指向:右侧容器内端口号,服务器端口不能重复,如果多个容器多个应用,需要nginx反响代理
-v 文件存储,左侧为映射到本地:右侧为容器内文件夹,防止镜像过大,迁移困难
--privileged: 和最后的参数/usr/sbin/init共同使用 才会有更高的权限控制
--name: 自定义容器启动的名称
centos:7.3.1611: 镜像名称 如果本地没有 会从网络上下载
也可以加入其它的参数 如-m 8G --cpus="4"
-m 8G :内存分配为8G
--cpus="4": 分配cpu核心总数为4
podman exec -i -t 7f5d968e2cf2 /bin/bash
-i: 允许你对容器进行交互
-t: 在新容器内指定一个伪终端或终端
243c32535da7:容器id可以用podman ps -a查看 也可以用名称代替
7、容器如果是挺值得,开启命令podman start mytest(容器名称)#默认centos源
[root@slave02 ~]# yum -y module install container-tools #容器工具基于模块
[root@slave02 ~]# yum -y install podman-docker #安装docker兼容包(可选)
版本[root@slave02 ~]# podman -v
podman version 3.3.0-dev
仓库[root@slave02 ~]# podman help|head -15
Manage pods, containers and images
Usage:
podman [options] [command]
Available Commands:
attach Attach to a running container
auto-update Auto update containers according to their auto-update policy
build Build an image using instructions from Containerfiles
commit Create new image based on the changed container #基于修改的容器创建新的容器
container Manage containers
cp Copy files/folders between a container and the local filesystem
create Create but do not start a container
diff Display the changes to the object's file system
events Show podman events
....
镜像加速器[root@slave02 ~]# cp /etc/containers/registries.conf /backup/registries.conf.back #备份一下
[root@slave02 ~]# vim /etc/containers/registries.conf
unqualified-search-registries = ["docker.io"] #非限定搜索登记处
[[registry]]
prefix = "docker.io"
location = "x" #x是阿里加速镜像地址
拉取镜像[root@slave02 ~]# podman pull nginx
6.运行一个web容器#准备html页面内容
[root@192 ~]# cat /opt/webhtml/index.html
Go your own way, see your own scenery, surpass others without complacency, and be surpassed without losing ambition
#运行一个守护web容器进程,将/opt/webhtml目录内容映射到容器的/usr/share/nginx/html存放网页的位置
[root@192 ~]# podman run -d --name web -p 8888:80 -v /opt/webhtml:/usr/share/nginx/html nginx
3528e6d5148bcf980f0df5708a82419d3485a33d1d16d722db3e880cc103cd2c
[root@podman ~]# curl 192.168.136.129:8888
Go your own way, see your own scenery, surpass others without complacency, and be surpassed without losing ambition
#容器的ip
[root@podman ~]# podman inspect web|grep IPAddress
"IPAddress": "10.88.0.6",
"IPAddress": "10.88.0.6",
#宿主机的ip
[root@podman ~]# ip r
192.168.136.0/24 dev ens33 proto kernel scope link src 192.168.136.129 metric 100
#由于进行了端口绑定,所以直接 curl 192.168.136.129:8888即可访问
进入后台web容器,查看服务状态[root@podman ~]# podman exec -it web bash
root@3528e6d5148b:/# service nginx status
[ ok ] nginx is running. #运行中
修改容器业务内容#修改宿主机/opt/webhtml/index.html即可
[root@podman ~]# cat /opt/webhtml/index.html
Go your own way, see your own scenery, surpass others without complacency, and be surpassed without losing ambitionRHCAS
RHCE RHCA
#进行访问
[root@podman ~]# curl 192.168.136.129:8888
Go your own way, see your own scenery, surpass others without complacency, and be surpassed without losing ambitionRHCAS
RHCE RHCA
#进入容器查看内容是否修改
[root@podman ~]# podman exec -it web bash
root@3528e6d5148b:/# cat /usr/share/nginx/html/index.html
Go your own way, see your own scenery, surpass others without complacency, and be surpassed without losing ambitionRHCAS
RHCE RHCA
暂停与删除容器#暂停
[root@podman ~]# podman stop web
web
[root@podman ~]# podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3528e6d5148b docker.io/library/nginx:latest nginx -g daemon o... 25 minutes ago Exited (0) 16 seconds ago 0.0.0.0:8888->80/tcp web
#删除
[root@podman ~]# podman rm web
3528e6d5148bcf980f0df5708a82419d3485a33d1d16d722db3e880cc103cd2c
#或强制删除运行中的容器
[root@podman ~]# podman rm -f web
3528e6d5148bcf980f0df5708a82419d3485a33d1d16d722db3e880cc103cd2c
[root@podman ~]# podman run --name web -d -p 8080:80 -v /opt/webhtml:/usr/shar/nginx/html nginx
910db3ab6bd1ef18e5fd0afe1844912f0b89334b7b8ab758353a948a1b55282a
基于web容器,在优先级一般的/etc/systemd/system内[root@192 ~]# cd /etc/systemd/system/
[root@podman user]# podman generate systemd --
--container-prefix (Systemd unit name prefix for containers)
--files {生成.service文件,而不是打印到标准输出}
--format (Print the created units in specified format (json)) #以指定的格式打印单元文件
--name (Use container/pod names instead of IDs) #创建新容器,而不是使用现有的容器
--new (Create a new container instead of starting an existing one)#(跳过标头生成)
--no-header (Skip header generation)
--pod-prefix (Systemd unit name prefix for pods)
--restart-policy (Systemd restart-policy)
--separator (Systemd unit name separator between name/id and prefix)
--time (Stop timeout override)
[root@192 system]# podman generate systemd --name web --files --new
/etc/systemd/system/container-web.service
查看生成的单元文件[root@192 system]# cat container-web.service
# container-web.service
# autogenerated by Podman 3.3.0-dev #podman 3.3.0-dev自动生成
# Tue Aug 17 13:03:13 CST 2021 #8月17日星期二13:03:13 CST 2021
[Unit] #单元
Description=Podman container-web.service #描述
Documentation=man:podman-generate-systemd(1) #帮助以及生成的系统
Wants=network-online.target #网络
After=network-online.target
RequiresMountsFor=%t/containers #前面不重要直接跳过
[Service]
Environment=PODMAN_SYSTEMD_UNIT=%n
Restart=on-failure #故障时重新启动
TimeoutStopSec=70 #超时时间
ExecStart=/usr/bin/podman run --sdnotify=conmon --cgroups=no-conmon --rm --replace --name web -d -p 8080:80 -v /opt/webhtml:/usr/shar/nginx/html nginx #执行开始为/usr/bin/podman 运行刚才创建的容器
Type=notify
NotifyAccess=all
[Install]
WantedBy=multi-user.target default.target
删除刚才的容器[root@podman ~]# podman rm web
910db3ab6bd1ef18e5fd0afe1844912f0b89334b7b8ab758353a948a1b55282a
[root@podman ~]# podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
设置开机自启[root@192 ~]# systemctl daemon-reload
[root@192 ~]# systemctl enable --now container-web.service
Created symlink /etc/systemd/system/multi-user.target.wants/container-web.service → /etc/systemd/system/container-web.service.
Created symlink /etc/systemd/system/default.target.wants/container-web.service → /etc/systemd/system/container-web.service.
[root@192 user]# podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b0c7709cb00e docker.io/library/nginx:latest nginx -g daemon o... 15 seconds ago Up 16 seconds ago 0.0.0.0:8080->80/tcp web
无根root模式设置容器和上面这种方式大同小异#需要运行loginctl enable-linger命令,使用户服务在服务器启动时自动启动即可
[containers@serverb ~]$ loginctl enable-linger
https://github.com/docker/compose/releases
二、将下载的compose文件 "docker-compose-Linux-x86_64" 改名为 "docker-compose"# sudo mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
四、添加可执行权限# sudo chmod +x /usr/local/bin/docker-compose
五、验证# docker-compose -v
docker-compose version 1.29.2, build unknown
ls -l docker
cp docker/* /usr/bin/
[root@localhost local]# tar xvf docker-19.03.9.tgz
docker/
docker/docker-init
docker/runc
docker/docker
docker/docker-proxy
docker/containerd
docker/ctr
docker/dockerd
docker/containerd-shim
[root@localhost local]# ls -l docker
total 195504
-rwxr-xr-x. 1 lr lr 32751272 May 14 17:29 containerd
-rwxr-xr-x. 1 lr lr 6012928 May 14 17:29 containerd-shim
-rwxr-xr-x. 1 lr lr 18194536 May 14 17:29 ctr
-rwxr-xr-x. 1 lr lr 61113382 May 14 17:29 docker
-rwxr-xr-x. 1 lr lr 68874208 May 14 17:29 dockerd
-rwxr-xr-x. 1 lr lr 708616 May 14 17:29 docker-init
-rwxr-xr-x. 1 lr lr 2928514 May 14 17:29 docker-proxy
-rwxr-xr-x. 1 lr lr 9600696 May 14 17:29 runc
[root@localhost local]# mv docker/* /usr/bin/
[root@localhost local]#
vim /etc/systemd/system/docker.service
添加文件内容:[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
chmod +x /etc/systemd/system/docker.service
systemctl daemon-reload
#开机启动systemctl enable docker.service
启动dockersystemctl start docker
例1.使用原版镜像进行安装系统,到达输入"用户名"时,不要输入,按下Ctrl+Shift+F3快捷键组合,即可直接进入"审核模式",到达桌面后会自动弹出sysprep.exe运行窗口。在这个模式(默认为管理员账户)下可以进行安装软件,驱动等。
例2.在安装完成的系统里,运行sysprep.exe,选择"进入审核模式",重启后和例1情况一样。
例3.在安装完成的系统里,运行sysprep.exe,选择"进入系统全新体验(OOBE)",重启后又到达了输入"用户名"的地方。
简要说明:OEM厂商在预装系统时进入"审核模式",安装软件及驱动等,作为测试。通常购买品牌电脑时,第一次开机会出现:正在为首次使用系统做准备。。。然后设置用户名等,其实系统早已安装到位,就差最后一步,通过上面的说明应该很清楚这是怎么做到的了。通常我们在做封装系统时,都是选用"进入系统全新体验(OOBE)","审核模式"对于普通用户来说没有必要也没有什么特别的好处,相反每次开机还有窗口弹出。multipass set client.primary-name=first
$ multipass start
Launched: first
Mounted '/home/ubuntu' into 'first:Home'
$ multipass stop
$ multipass launch eoan
Launched: calm-chimaera
$ multipass set client.primary-name=calm-chimaera
$ multipass suspend
$ multipass set client.primary-name=chopin
$ multipass start
Launched: chopin
Mounted '/home/ubuntu' into 'chopin:Home'
$ multipass list
Name State IPv4 Image
chopin Running 10.122.139.63 Ubuntu 18.04 LTS
calm-chimaera Suspended -- Ubuntu 19.04
first Stopped -- Ubuntu 18.04 LTS
multipass launch --name foo
Run commands in that instance, try running bash (logout or ctrl-d to quit)multipass exec foo -- lsb_release -a
Pass a cloud-init metadata file to an instance on launch. See using cloud-init with multipass for more detailsmultipass launch -n bar --cloud-init cloud-config.yaml
See your instancesmultipass list
Stop and start instancesmultipass stop foo bar
multipass start foo
Clean up what you don't needmultipass delete bar
multipass purge
Find alternate images to launch with multipassmultipass find
Get helpmultipass help
multipass help <command>
Now don't forget you still have 'foo' running. To learn more about Multipass keepsudo snap install multipass
Install Multipass on MacOSsudo multipass set local.driver=virtualbox