docker离线安装本地源
时间: 2023-11-20 21:59:29 浏览: 48
以下是使用docker搭建离线yum源的步骤:
1. 在一台联网的机器上,使用以下命令拉取centos官方镜像:
```shell
docker pull centos
```
2. 运行容器并进入容器:
```shell
docker run -it --name centos centos /bin/bash
```
3. 在容器中安装createrepo和yum-utils:
```shell
yum install -y createrepo yum-utils
```
4. 将需要的rpm包上传到容器中,例如将所有的rpm包上传到/root/rpms目录下。
5. 在上传的rpm包所在目录下执行以下命令生成repodata:
```shell
createrepo .
```
6. 在容器中安装httpd:
```shell
yum install -y httpd
```
7. 启动httpd服务:
```shell
systemctl start httpd
```
8. 将生成的repodata目录复制到httpd的根目录下:
```shell
cp -r repodata /var/www/html/
```
9. 退出容器并保存容器的修改:
```shell
exit
docker commit centos mycentos
```
10. 运行新的容器并将httpd服务暴露出来:
```shell
docker run -d -p 80:80 mycentos /usr/sbin/httpd -D FOREGROUND
```
11. 在需要使用离线yum源的机器上,将该机器的yum源配置文件备份并修改为以下内容:
```shell
[base]
name=CentOS-$releasever - Base
baseurl=http://<ip_address_of_your_docker_host>/repodata/
enabled=1
gpgcheck=0
```
其中,`<ip_address_of_your_docker_host>`为运行httpd服务的机器的IP地址。
12. 执行`yum makecache`命令更新缓存即可使用离线yum源。