docker构建镜像

一般来说,我们所说的“构建镜像”并不是真正的从零构建一个全新的镜像,而是修改一个已有的基础镜像(如ubuntu)。

创建Docker Hub账号

(1) 如果要存储和分发我们构建的新镜像,那么可以将镜像发布到 Docker Hub 或者自己私有的Registry上面。所以需要先在 Docker Hub 创建一个账号。

(2)创建账号后,使用 docker login命令就可以登录到Docker Hub了。

# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: sweeneys
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

如上所示,登录的个人认证信息被保存到 ~/.docker/config.json

使用commit命令创建镜像

1、创建容器

创建一个基于ubuntu镜像的容器,后续会以这个容器为基础进行修改,从而形成新的镜像。

# docker run -it ubuntu /bin/bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
7ddbc47eeb70: Pull complete 
c1bbdc448b72: Pull complete 
8c3b70e39044: Pull complete 
45d437916d57: Pull complete 
Digest: sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d
Status: Downloaded newer image for ubuntu:latest

2、添加Apache软件包

Apache软件包在ubuntu官方源上的名字为apache2。

root@51753edb3a70:/# apt-get  update
root@51753edb3a70:/# ap
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值