参考博客:https://blog.csdn.net/SunJW_2017/article/details/105058500
1. 拉取一个基础操作系统
docker pull centos
2 基于镜像启动一个容器
我的docker是装在centos虚拟机上的,虚拟机可以访问网络,为了确保生成的容器可以访问网络,在执行docker run
命令时,需要注意设置一下参数:
docker run -it --network host centos /bin/bash
与一般的操作不同的是,这里我指定了--network
的值,这个参数的默认值是bridge
,如果不加更改,在我的尝试中容器内是无法访问网络的。参数值host
的意思就是说,容器可以和其所在主机共用一个网络。
3 安装wget
cd /etc/yum.repos.d/
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
yum makecache
yum update -y
yum install wget
4 安装conda
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
Miniconda安装包的路径可以去官网找到,还有各种不同的python版本,就不多说明了。
这样,下载的*.sh
文件就出现在了当前路径下。接下来是安装:
sh Miniconda3-latest-Linux-x86_64.sh
source /root/.bashrc
按几次S,一路采用默认的设置就好。
5. 生成镜像
当我们在容器里面的工作完成之后,输入exit跳出容器,然后利用docker commit命令基于该容器生成一个新的镜像:
docker commit -a "author name" [IMAGE ID] my-first-image
[IMAGE ID] =镜像ID
6.镜像到文件
最后一步,就是将镜像保存为文件:
docker save -o /a-python-base-image [NEW IMAGE ID]
[NEW IMAGE ID] =新提交镜像的ID
7.推送进行至阿里云docker
【登录阿里云docker】
(base) [root@izrj97vwjyj7pi6cg9jveez ~]# docker login --username=xxx-registry.us-west-1.aliyuncs.com
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[设置tag]
(base) [root@izrj97vwjyj7pi6cg9jveez ~]# docker tag 981035f11a7c registry.us-west-1.aliyuncs.com/xxx/img:1.0
[push镜像]
(base) [root@izrj97vwjyj7pi6cg9jveez ~]# docker push registry.us-west-1.aliyuncs.com/xxx/img:1.0