Docker 镜像添加模块

1. 使用root用户进入一个新容器,不要用 --rm .否则退出容器的时候,容器没有了

docker run --user 0 -it --name python01 python:latest bash

2. 在容器中添加你要的功能,然后退出容器

apt install ...
npm install -g n 
pip3 install ...

3. commit 刚才操作的容器成 image (python:v1 名称和版本号可以自己定义)

docker commit python01 python:v1

4. 查看刚才 commit 操作的 image, 此时 image 里面就包含了刚才添加的新增的模块了

root@test:~# docker images 

REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE

python           v1                  e4f2c829d1eb        23 minutes ago      4.42GB

5. 将新的 image 保存成 tar 压缩文件,给其他人使用,统一开发环境

docker save python:v1 -o test_cpu.tar

6. 别人拿到 test_cpu.tar 文件后使用 docker load 加载 image

docker load -i test_cpu.tar

此时使用 docker images 就可以看到刚才的导入的 image 了

root@test:~# docker images 

REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE

python          v1                  e4f2c829d1eb        23 minutes ago      4.42GB

7. push 镜像到指定 Docker Hub 仓库

docker push 172.10.10.10:5555/python-3.6:pytest

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容