基于screach创建 rockylinux:9 镜像, 要求除内部命令外,还可以使用 curl dig ipconfig 三条命令
时间: 2024-02-07 12:04:14 浏览: 149
可以通过以下步骤基于scratch创建一个包含curl、dig和ipconfig命令的Rocky Linux 9镜像:
1. 创建一个Dockerfile文件:
```
FROM scratch
ADD rockylinux-9.tar.xz /
ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
RUN mkdir /usr/share/man/man1 \
&& yum update -y \
&& yum install -y curl \
&& yum install -y bind-utils \
&& yum install -y iproute \
&& yum clean all \
&& rm -rf /var/cache/yum
```
2. 构建Docker镜像:
```
docker build -t rockylinux:9 .
```
3. 运行容器:
```
docker run -it rockylinux:9 /bin/bash
```
在容器中,你可以使用curl、dig和ipconfig命令,例如:
```
[root@container /]# curl --version
curl 7.76.1 (x86_64-redhat-linux-gnu) libcurl/7.76.1 OpenSSL/1.1.1k zlib/1.2.11 brotli/1.0.9 libidn2/2.3.2 libpsl/0.7.1 (+libidn2/2.3.2) libssh/0.9.5/openssl/zlib nghttp2/1.43.0
Release-Date: 2021-04-14
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS brotli GSS-API HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz Metalink NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets
[root@container /]# dig google.com
; <<>> DiG 9.11.26-RedHat-9.11.26-4.el8_4 <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10846
;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;google.com. IN A
;; ANSWER SECTION:
google.com. 67 IN A 142.250.72.238
google.com. 67 IN A 142.250.72.110
google.com. 67 IN A 142.250.72.14
google.com. 67 IN A 142.250.72.174
google.com. 67 IN A 142.250.72.206
google.com. 67 IN A 142.250.72.78
;; Query time: 25 msec
;; SERVER: 192.168.65.1#53(192.168.65.1)
;; WHEN: Wed Nov 24 03:34:59 UTC 2021
;; MSG SIZE rcvd: 127
[root@container /]# ipconfig
bash: ipconfig: command not found
```
如上所示,你可以成功使用curl、dig和ipconfig命令,但是ipconfig命令并不可用,你可以使用ip命令替代。
阅读全文