怎样从仓库下载的镜像, 变成容器, 并在容器中制作项目, 再将容器变成镜像, 然后将镜像推送到仓库?
一: 从官网下载镜像
官方的 https://hub.docker.com/ 提供了数十万个镜像提供大家下载
以拉取个人公有 centos7.3 镜像为例:
拉取方式为
- # docker pull 用户 / 仓库: 标签
- docker pull kennyyaohong/public:centos7.3
二: 进行项目
1. 启动容器
- # -it 以交互模式启动一个容器
- #--name 命名容器
- #-d 后台运行容器, 并返回容器 ID
- #docker run -it --name 定义容器名 -d 镜像名: 标签
- docker run -it --name container_centos7.3 -d kennyyaohong/public:centos7.3
- docker ps
- CONTAINER ID IMAGE NAMES COMMAND CREATED STATUS PORTS
4bd480b4ac28 kennyyaohong/public:centos7.3 container_centos7.3 "/bin/bash" 4 seconds ago Up 3 seconds
2. 进入容器
- #exec : 在运行的容器中执行命令
- #-d : 分离模式: 在后台运行
- #-i : 即使没有附加也保持 STDIN 打开
- #-t : 分配一个伪终端
- docker exec -ti container_centos7.3 /bin/bash
- [root@d3dfc0a17d1a /]#
3. 进行项目
- [root@4bd480b4ac28 /]# mkdir project
- [root@4bd480b4ac28 /]# cd project/
- [root@4bd480b4ac28 project]# ls
- [root@4bd480b4ac28 project]# vi test.sh
- [root@4bd480b4ac28 project]# sh test.sh
- hello
- #-a : 提交的镜像作者;
- #-c : 使用 Dockerfile 指令来创建镜像;
- #-m : 提交时的说明文字;
- #-p : 在 commit 时, 将容器暂停.
- # docker commit -m "提交说明文字" -a "作者" 要提交的容器名 提交后的镜像名: 提交后的镜像 tag 名
- docker commit -m "my_project" -a "kennyyaohong" container_centos7.3 myproject_centos7.3:centos7.3
- sha256:e12a9ec48ab76d4114e4d80293eb994bafb5d49e974143766d08ab9f74a2d193
- # 容器变为镜像后的
- host-172-17-17-115:~ # docker images;
- REPOSITORY TAG IMAGE ID CREATED SIZE
- myproject_centos7.3 centos7.3 e12a9ec48ab7 2 seconds ago 258MB
- #docker tag 镜像 id 要推入仓库的用户名 / 要推入的仓库名: 新定义的 tag
- docker tag e12a9ec48ab7 kennyyaohong/public:myproject_centos7.3
- #docker push 要推入仓库的用户名 / 要推入的仓库名: 镜像标签
- docker push kennyyaohong/public:myproject_centos7.3
- The push refers to a repository [docker.io/kennyyaohong/public]
- 193b0484e158: Layer already exists
- 34e7b85d83e4: Layer already exists
- myproject_centos7.3: digest: sha256:5ffa998f3fc91e965d3b2e65ceefbc30a0bce49359058fba39e9386206a84bdc size: 948
来源: https://www.cnblogs.com/yaohong/p/9221800.html