docker 操作命令

安装docker 前我把yum源设置成了阿里云
yum config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

1 docker 在linux上的安装 yum install docker-ce docker分为(ce社区版)和(ee企业版)
2 查看docker的版本 docker -v
3 查看nginx docker search nginx
3 拉取nginx最新的镜像 docker pull nginx:latest latest 最新的,如果下载其他的版本需要手动到https://registry.hub.docker.com查 询
4 查看拉取后的nginx 镜像

[root@iZ2ze0r5hel5o14s8g2013Z ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED      SIZE
nginx        latest    4f380adfc10f   8 days ago   133MB

5 根据镜像生成一个容器

[root@iZ2ze0r5hel5o14s8g2013Z nginx]# docker run --name  nginx-test  -p 80:8080  -d -v  /etc/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf -v /etc/nginx/nginx.conf:/etc/nginx/nginx.conf  nginx 
d4453e6927d3b93c0bb5587a0c2d34f0c71d92410fd7887d21743ab0f3ab7c5e

–name 容器名字
-p 端口号 宿主主机:容器端口号
-d 后台运行
nginx 镜像名字

6 关闭容器/删除容器/删除镜像

  docker  stop nginx-test //关闭容器
  docker rm nginx-test //删除容器
  docker rmi  nginx:lastest //删除镜像  [respository:tag] nginx为仓库名  lastest为tag名字

7 修改nginx中的配置,我们先在宿主主机上修改好nginx的配置文件,然后停掉容器nginx-test,并删掉容器nginx-test,新建容器的时候加上-v 参数

[root@iZ2ze0r5hel5o14s8g2013Z conf.d]# docker run --name  nginx-test  -p 80:8080  -d -v  /etc/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf -v /etc/nginx/nginx.conf:/etc/nginx/nginx.conf  nginx 
250a6443b7036d80812bf304f830104796c715a3f5ca933b4324f3312a214511

-v 后紧跟的是宿主主机的自定义配置文件,冒号后跟的docker容器中的配置文件
命令最后是 镜像的名字

8 如果我们本地的服务器配置做出一些修改后,想把环境整体复制.那我们需要先把该容器打包成镜像,通过镜像的拉取,在另一台服务器瞬间还原环境.

[root@iZ2ze0r5hel5o14s8g2013Z conf.d]# docker commit  nginx-test nginx:2.0
sha256:defc44f40e4c764e249d346064f01fa16612c40515902a13c43eae7fbf9ae0f1
[root@iZ2ze0r5hel5o14s8g2013Z conf.d]# docker images 
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
nginx        2.0       defc44f40e4c   23 seconds ago   133MB
nginx        1.1       d1b15e5a451e   7 minutes ago    133MB
nginx        latest    4f380adfc10f   8 days ago       133MB

根据新生成的镜像运行一个实例

[root@iZ2ze0r5hel5o14s8g2013Z conf.d]# docker images 
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
nginx        2.0       defc44f40e4c   23 seconds ago   133MB
nginx        1.1       d1b15e5a451e   7 minutes ago    133MB
nginx        latest    4f380adfc10f   8 days ago       133MB
[root@iZ2ze0r5hel5o14s8g2013Z conf.d]# docker run --name nginx-test2 -p 80:8080  nginx:2.0

9 把镜像提交或共享给其他人

(1)新生成的镜像只是在本地,我们可以上传到远程仓库。(私有或者公有) 我们现在本地服务器上运行一个私有的仓库.这里docker公司已经给我们提供了一镜像registry帮助我们建立自己的私有仓库,我们pull 并run就可以

[root@iZ2ze0r5hel5o14s8g2013Z ~]# docker pull registry:2
2: Pulling from library/registry
ddad3d7c1e96: Pull complete 
6eda6749503f: Pull complete 
363ab70c2143: Pull complete 
5b94580856e6: Pull complete 
12008541203a: Pull complete 
Digest: sha256:aba2bfe9f0cff1ac0618ec4a54bfefb2e685bbac67c8ebaf3b6405929b3e616f
Status: Downloaded newer image for registry:2
docker.io/library/registry:2
[root@iZ2ze0r5hel5o14s8g2013Z ~]# docker run -p 5000:5000 --name myregistry -d registry:2 
45a5d468d4b7606c2e874781f6844612aca473b05f9bdcf887dfcbb75f685435

(2)现在我们push一个共享镜像到该仓库(使用docker push 推送,tag表示推送的地址,所以需要先把推送的镜像tag一下)

[root@iZ2ze0r5hel5o14s8g2013Z ~]# docker tag nginx:2.0  localhost:5000/nginx:2.0
[root@iZ2ze0r5hel5o14s8g2013Z ~]# docker images 
REPOSITORY             TAG       IMAGE ID       CREATED          SIZE
nginx                  2.0       defc44f40e4c   59 minutes ago   133MB
localhost:5000/nginx   2.0       defc44f40e4c   59 minutes ago   133MB
registry               2         1fd8e1b0bb7e   2 months ago     26.2MB
[root@iZ2ze0r5hel5o14s8g2013Z ~]# docker push localhost:5000/nginx:2.0 
The push refers to repository [localhost:5000/nginx]
89c86438a08e: Pushed 
3b3d3cd6392a: Pushed 
bd4ec23d9941: Pushed 
0bb5241e3aa0: Pushed 
c6d74dcb7fe7: Pushed 
b50a193ebf2e: Pushed 
165eb6c3c0d3: Pushed 
cf388fcf3527: Pushed 
2418679ca01f: Pushed 
764055ebc9a7: Pushed 
2.0: digest: sha256:40565e62c7e57e4247139abefd838dc774520443aa3a9741b580688e4458780d size: 2399

(3)推送完成后我们就可以看下推送的镜像,方便其他的人拉取该镜像.我们可以通过访问 127.0.0.1:500/v2/_catalog 或者 127.0.0.1:5000/v2/registry/tags/list 来查看
在这里插入图片描述
在这里插入图片描述
其他的小伙伴就可以命令行获取你的镜像了(当然你的端口5000要对外开放)

docker pull  ip:5000/nginx:2.0

10 docker 安装php

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值