0%

RHCSA (EX200) - 容器 nginx(附加题)

容器 nginx

利用注册服务器上的 nginx 镜像,创建一个名为 nginx 的容器

面向 wallah 用户,配置一个 systemd 服务

该服务命名为 container-nginx,并在系统重启时自动启动,无需干预

/home/wallah/www 下创建文件 index.html,内容为 hello nginx

将服务配置为在启动时自动将 /home/wallah/www 挂载到容器中的 /usr/share/nginx/html

将容器主机上的端口 8080 映射到容器上的端口 80

1
2
3
4
5
6
7
8
9
10
11
12
13
[wallah@node1 ~]$ man -k registries
containers-registries.conf (5) - Syntax of System Registry Configuration File
containers-registries.d (5) - Directory for various registries configurations
skopeo (1) - - Command line utility used to interact with local and remote container images and container image registries
skopeo-sync (1) - Synchronize images between container registries and local directories.
[wallah@node1 ~]$ man containers-registries.conf
[wallah@node1 ~]$ cat /etc/containers/registries.conf
[registries.search]
registries = ['registry.access.redhat.com', 'registry.redhat.io', 'docker.io']
[registries.insecure]
registries = []
[registries.block]
registries = []
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
[root@node1 ~]# ssh wallah@localhost 
[wallah@node1 ~]$ mkdir /home/wallah/www
[wallah@node1 ~]$ echo "hello nginx" > /home/wallah/www/index.html
[wallah@node1 ~]$ podman login registry.domain250.example.com
Username: admin
Password:
Login Succeeded!
[wallah@node1 ~]$ podman search registry.domain250.example.com/
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
example.com registry.domain250.example.com/rhel8/mariadb-103 0
example.com registry.domain250.example.com/rhel8/httpd-24 0
example.com registry.domain250.example.com/library/nginx 0
example.com registry.domain250.example.com/ubi7/ubi 0
example.com registry.domain250.example.com/ubi8/ubi 0
example.com registry.domain250.example.com/rhel8/rsyslog 0
[wallah@node1 ~]$ podman pull registry.domain250.example.com/library/nginx
Trying to pull registry.domain250.example.com/library/nginx...
Getting image source signatures
Copying blob 2ee525c5c3cc done
Copying blob ebd81fc8c071 done
Copying blob d15953c0e0f8 done
Copying blob d121f8d1c412 done
Copying blob 655316c160af done
Copying config 7e4d58f0e5 done
Writing manifest to image destination
Storing signatures
7e4d58f0e5f3b60077e9a5d96b4be1b974b5a484f54f9393000a99f3b6816e3d
[wallah@node1 ~]$ podman run -d --name nginx -p 8080:80 -v /home/wallah/www:/usr/share/nginx/html:Z registry.domain250.example.com/library/nginx
715b0d5e63c1fffd41f40910f017b0a3d5884310cd8af9ca5867480c514563bb
[wallah@node1 ~]$ curl localhost:8080
hello nginx
[wallah@node1 ~]$ podman stop nginx
715b0d5e63c1fffd41f40910f017b0a3d5884310cd8af9ca5867480c514563bb
[wallah@node1 ~]$ loginctl enable-linger
[wallah@node1 ~]$ loginctl show-user wallah
...
Linger=yes
[wallah@node1 ~]$ mkdir -p ~/.config/systemd/user/
[wallah@node1 ~]$ cd ~/.config/systemd/user/
[wallah@node1 user]$ podman generate systemd --name nginx --files
/home/wallah/.config/systemd/user/container-nginx.service
[wallah@node1 user]$ systemctl --user enable --now container-nginx.service
Created symlink /home/wallah/.config/systemd/user/multi-user.target.wants/container-nginx.service → /home/wallah/.config/systemd/user/container-nginx.service.
Created symlink /home/wallah/.config/systemd/user/default.target.wants/container-nginx.service → /home/wallah/.config/systemd/user/container-nginx.service.
[wallah@node1 user]$ curl localhost:8080
hello nginx