docker系列学习(二)

一. 目标

制作一个小demo

  1. 熟悉一下docker镜像仓库的login和logout
  2. 初步了解一下使用Dockerfile制作镜像的过程
  3. 熟悉一下个人镜像仓库的镜像推送和拉取

二. docker仓库的登录和退出

  1. docker默认镜像仓库地址为: https://hub.docker.com/
  1. 先在镜像仓库注册一个账号
  2. 在终端执行登录命令: docker login3. 在终端执行退出命令: docker logout
  1. 可以使用阿里云docker镜像仓库, 地址为: https://cr.console.aliyun.com/cn-shanghai/instances/repositories
  1. 在阿里云镜像仓库注册一个账号
  2. 在终端执行登录命令: docker login --username=用户名 registry.cn-shanghai.aliyuncs.com
  3. 在终端执行退出命令: docker logout registry.cn-shanghai.aliyuncs.com

三. 使用Dockerfile制作镜像

  1. 新建Dockerfile文件
  2. 完成Dockerfile的编写(简单编写,此处不是重点…)
FROM nginx
RUN echo 'hello docker!!!' > /usr/share/nginx/html/index.html
  1. FROM nginx
    FROM关键字:定义基础镜像, 此句意思是基础镜像为: nginx:latest
  2. RUN echo ‘hello docker!!!’ > /usr/share/nginx/html/index.html
    RUN关键字: RUN命令是Dockerfile执行命令的核心部分。它接受命令作为参数并用于创建镜像
    此句意思是修改/usr/share/nginx/html/index.html该文件内容为: hello docker!!!
    /usr/share/nginx/html/index.html这个文件是nginx默认展示页
  1. 运行Dockerfile文件

执行命令: docker build -t [镜像名]:[版本号] . (点不要忘记了)

  1. 查看制作好的镜像

执行查看镜像命令: docker images

四. 运行制作好的镜像

  1. 使用运行镜像命令: docker run --name nginx_hello_90 -p 90:80 -d nginx_hello:v1
  2. 查看运行效果(端口为90):

五. 使用个人镜像仓库推送和拉取(以docker hub为例)

  1. 登录docker hub
  2. 重命名nginx_hello镜像(打上仓库标签)命令: docker tag 6e055adeae72 wangxq2019/nginx_hello:v1

  1. 推送打好标签的新镜像: docker push wangxq2019/nginx_hello:v1

  1. 运行wangxq2019/nginx_hello镜像, 看是否能成功访问

wangxq2019/nginx_hello镜像实例化一个容器命令: docker run --name nginx_hello_91 -p 91:80 -d wangxq2019/nginx_hello:v1
查看结果(端口为91):

  1. 删除本地的wangxq2019/nginx_hello镜像(需要停止对应的容器), 然后从远处拉取镜像到本地
  1. 停止容器nginx_hello_91命令: docker stop nginx_hello_91
  2. 删除容器命令: docker rm nginx_hello_91
  3. 删除wangxq2019/nginx_hello镜像命令: docker rmi wangxq2019/nginx_hello:v1
  4. 从docker hub 拉取wangxq2019/nginx_hello镜像: docker pull wangxq2019/nginx_hello:v1
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值