自制Docker镜像并上传到腾讯云

服务器配置

    1.首先安装docker

    2.然后修改docker的服务器位置,腾讯的为https://mirror.ccs.tencentyun.com

    3.下载ubuntu镜像 git pull ubuntu

    4.打开腾讯云容器服务,注册并登陆

    5.选择镜像仓库,点击我的镜像,点击命名空间,新建一个命名空间,名称自拟

    6.新建一个镜像,名称自拟,最好命名为ubuntu

    7.点击刚才新建的ubuntu镜像

    8.根据使用指引,先push一个最初版本

本地镜像配置

    1.首先开启一个容器 docker run -it ubuntu /bin/bash

    2.刷新apt列表 apt-get update

    3.安装vim apt-get install vim (过程中可能会出错,重新运行一遍就好了)

    4.备份apt源文件,防止修改错误
    cd /etc/apt
    cp sources.list sources.list.bak

    5.修改apt源文件
    vim sources.list

    6.把里面的内容全部删除,然后加入下面文字

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

    7.更新apt apt-get update,apt-get upgrade

    8.安装python apt-get install python ,输入python查看是否安装成功

    9.安装pip apt-get install python-pip,输入pip看是否安装成功,这步时间较长

    10.安装wget apt-get install wget

    11.安装binwalk apt-get install binwalk

    12.安装网络工具 apt-get install net-tools

    13.安装ssh apt-get install ssh

    14.文件传输指令 docker cp 本地文件路径 ID全称:容器路径
    ID全称获取方法:docker inspect -f ‘{{.Id}}’ Linux4CTF
    '1f30a1412230036093d2c812db35b6269122e5334115f07b68c2787006027c0b'

    15.安装git apt-get install git

    16.把容器保存为新的镜像 docker commit 1f30a1412230 ubuntu:v1.0

    17.按照指引上传镜像,因为新安装了不少东西,所以容量较大,大约1G,需要上传一阵子

从本地拉取刚才搭建的镜像

docker login --username=100009506226 ccr.ccs.tencentyun.com

docker pull ccr.ccs.tencentyun.com/eumenides/ubuntu:v1.0

这样就完成了自定义docker并上传到腾讯云的操作,若是大规模配置服务器之类的,可以用这种方法自制docker镜像,然后上传到腾讯云,最后只需在服务器集群执行docker pull指令就可大规模搭建服务器集群了。

同样的方法对于个人而言也可以用来备份本地工作环境,需要重新配置时只需一条指令便可省去环境搭建的痛苦,岂不美哉

点赞

发表评论

[2;3Rer>