VMware虚拟机Centos操作系统——配置docker,运行本地打包的镜像,进入conda环境(vmware,docker新手小白)

1.docker-centos运行sudo yum install -y yum-utils报错

遇到问题

解决:

进入**/etc/yum.repos.d**目录下找到 CentOS-Base.repo,执行下面两个命令:

bash 复制代码
cp  CentOS-Base.repo   CentOS-Base.repo.backup
 
vi CentOS-Base.repo 

进入后改成:

bash 复制代码
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#
 
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
#baseurl=http://vault.centos.org/7.9.2009/x86_64/os/
baseurl=http://vault.centos.org/7.9.2009/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
#baseurl=http://vault.centos.org/7.9.2009/x86_64/os/
baseurl=http://vault.centos.org/7.9.2009/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#$baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
#baseurl=http://vault.centos.org/7.9.2009/x86_64/os/
baseurl=http://vault.centos.org/7.9.2009/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
#baseurl=http://vault.centos.org/7.9.2009/x86_64/os/
baseurl=http://vault.centos.org/7.9.2009/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

上面主要修改的是:

1.mirror前面加了注释->#mirror

2.在gpgcheck=1上面加了一行代码具体看上面

然后wq保存下,执行下面两行命令:

bash 复制代码
sudo yum clean all
sudo yum makecache

执行阿里云源:

bash 复制代码
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

执行完成后进入**/etc/yum.repos.d**执行

bash 复制代码
 cat CentOS-Base.repo

看着镜像是阿里云的,在执行下

bash 复制代码
sudo yum clean all
sudo yum makecache

2.配置镜像加速器:

这里用的是阿里镜像,链接如下

阿里云登录 - 欢迎登录阿里云,安全稳定的云计算服务平台欢迎登录阿里云,全球领先的云计算及人工智能科技公司,阿里云为200多个国家和地区的企业、开发者和政府机构提供云计算基础服务及解决方案。阿里云云计算、安全、大数据、人工智能、企业应用、物联网等云计算服务。https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors

配置如下:(将下面蓝色框框内的命令在vmware里面疯狂运行就完事)

3.Centos安装---docker官网

CentOS | Docker DocsLearn how to install Docker Engine on CentOS. These instructions cover the different installation methods, how to uninstall, and next steps.https://docs.docker.com/engine/install/centos/

框框运行下面的命令

bash 复制代码
sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
bash 复制代码
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
bash 复制代码
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
bash 复制代码
sudo systemctl start docker

最后一步启动docker就成功了,可以运行 docker images看一下有没有显示docker镜像相关信息,如果有就说明运行docker成功

4.将电脑本地的.zip文件(里面保存.tar镜像)上传到虚拟机

4-1.使用SSH连接步骤:

a.在虚拟机中启动 SSH 服务
bash 复制代码
sudo systemctl start sshd
sudo systemctl enable sshd
b.查找虚拟机的IP地址
bash 复制代码
ip addr

找到类似192.168.x.x的IP地址

c.在主机上使用 SSH 连接到 CentOS 虚拟机
bash 复制代码
ssh [email protected]

your_username一般是root(看自己设置的)

d.输入密码后即可连接到虚拟机

此时说明已经通过ssh连接上了虚拟机

连接最后效果:

4-2.传输.zip文件

重新打开cmd,通过使用 scp 传输文件(此时你可以通过 SSH 访问虚拟机)
bash 复制代码
scp /Downloads/test.zip [email protected]:/home/test/
例如: 此成功案例

此时就将.zip文件传输到虚拟机上了,可以在虚拟机中通过ls查看文件中是否已经包含上传的test.zip文件,存在就说明上传成功啦啦啦啦

5.解压上传的.zip文件得到.tar镜像文件

5-1.首先安装unzip (如果原来没有安装过)

bash 复制代码
sudo yum install unzip

5-2.解压.zip文件

bash 复制代码
unzip /home/test.zip -d /home/test

此时可以用ls看/home/test目录下存在test.tar文件了

6.使用 Docker 运行镜像,进入conda

6-1.加载 Docker 镜像

bash 复制代码
docker load < /home/test/test.tar

6-2.加载成功后,运行 Docker 容器并进入

此命令为创建一个新容器并启动容器进入容器的终端
bash 复制代码
docker run -it --name test_container image_name /bin/bash

将 image_name 替换为刚才加载的镜像名称

或者 此命令为启动一个已有的容器并进入容器的终端
bash 复制代码
docker start <CONTAINER_ID or NAME>
docker exec -it <CONTAINER_ID or NAME> /bin/bash

这个命令会启动容器并进入 bash 终端,此时可用用docker ps -a查看已经有的容器名为test_container

6-3.进入容器后激活 Conda 环境

查看存在的conda环境
bash 复制代码
conda info --envs
激活conda环境
bash 复制代码
conda activate 环境名

过程中遇到问题:加载.tar镜像后,遇到的问题------docker images查看该镜像名称为<none>

使用以下命令为镜像重新指定名称和标签:

bash 复制代码
   docker tag <镜像 ID> new_image_name:new_tag

例如:

bash 复制代码
   docker tag 1234567890abcdef test:latest
相关推荐
点云SLAM10 分钟前
PyTorch 中contiguous函数使用详解和代码演示
人工智能·pytorch·python·3d深度学习·contiguous函数·张量内存布局优化·张量操作
尘浮72824 分钟前
60天python训练计划----day45
开发语言·python
sss191s29 分钟前
校招 java 面试基础题目及解析
java·开发语言·面试
哆啦A梦的口袋呀35 分钟前
基于Python学习《Head First设计模式》第六章 命令模式
python·学习·设计模式
努力搬砖的咸鱼37 分钟前
从零开始搭建 Pytest 测试框架(Python 3.8 + PyCharm 版)
python·pycharm·pytest
Calvex40 分钟前
PyCharm集成Conda环境
python·pycharm·conda
一千柯橘1 小时前
python 项目搭建(类比 node 来学习)
python
sduwcgg1 小时前
python的numpy的MKL加速
开发语言·python·numpy
大模型真好玩1 小时前
可视化神器WandB,大模型训练的必备工具!
人工智能·python·mcp
东方佑1 小时前
使用 Python 自动化 Word 文档样式复制与内容生成
python·自动化·word