构建自己的docker镜像 并打包提交

1.从远程仓库拉取一个纯净的 ubuntu 系统镜像

docker search ubuntu

2.创建并进入容器

docker run -itd --name="lanmp" -p 80:80 -p 3306:3306 -v ~/DockerShare:/kkshare ubuntu

-p 指向端口

-v  映射宿主目录的 DockerShare到容器内的/kkshar

3.操作容器

docker exec -it lanmp /bin/bash

4.更改apt-get的镜像源为 阿里云 在宿主~/DockerShare(容器/kkshare)创建sources.list 且内容如下,将sources.list替换掉容器内/etc/apt/sources.list

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

 

因为最新的ubuntu是 20. 如果是其他版本 参考 https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.3e221b11zw6Z9I

4.更新apt缓存.并安装 vim net-tools nginx (我这里只安装了nginx服务)

apt-get update && apt-get install -y vim net-tools nginx

5.为最新版本打上标签(因为下一步 我们要更新最新版本)

docker tag liuforhacker/kuangke:latest liuforhacker/kuangke:v2
liuforhacker/kuangke:latest 源镜像
liuforhacker/kuangke:v2 创建镜像+Tag

6.创建自己的镜像

docker commit -a "kuangke" -m "common environment" 1acda42edcfb liuforhacker/kuangke:v2

liuforhacker = 你的Docker ID 

 

 

7.把自己的镜像提交到 docker hub

docker push liuforhacker/kuangke:v2

参考文章

https://www.cnblogs.com/kevingrace/p/9599988.html

https://www.cnblogs.com/pjcd-32718195/p/11762079.html

https://www.cnblogs.com/franson-2016/p/13185972.html

 

      

posted @ 2021-02-04 10:05  狂客  阅读(463)  评论(0编辑  收藏  举报