自己构建一个Docker镜像

1,一样是需要在 https://www.docker.com/ 上有自己的账号

2,docker run -it ubuntu:latest 运行一个你需要的环境,也可以先pull下来再run

3,在环境里安装自己需要的组件,下面的例子是我安装了azure cli和terraform
docker run -it ubuntu:latest
apt update -y
apt upgrade -y
apt install -y curl wget sudo vim unzip


curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash


wget -O – https://apt.releases.hashicorp.com/gpg | sudo gpg –dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo “deb [arch=$(dpkg –print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main” | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform -y

curl “https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip” -o “awscliv2.zip”
unzip awscliv2.zip
sudo ./aws/install

3,创建image:不要退出刚才的容器新连接一个ssh
docker commit -m “description” -a “author” <容器id> repository:tag

“description”:描述信息。
“author”:作者名。
<容器id>:可以在就终端那里看到,形如root@2ce6712ef339:/#。可以看到<容器id>是2ce6712ef339。
reposiory:镜像仓库名,任取即可。
tag:镜像标签名,任取即可。
在本例中,生成镜像使用如下命令

docker commit -m “ubuntu-az-terrafrom” -a “Zhen Qin” 6d726081f0fa qinzhen/ubuntu-az-tf:latest

4,将自建的Docker镜像推送至Docker Hub
docker push qinzhen/ubuntu-az-tf:latest

评论已关闭。