docker_常用参数

查看容器 ps

-a, --all             Show all containers (default shows just running)
-f, --filter filter   Filter output based on conditions provided
    --format string   Pretty-print containers using a Go template
-n, --last int        Show n last created containers (includes all states) (default -1)
-l, --latest          Show the latest created container (includes all states)
      --no-trunc        Don't truncate output
-q, --quiet           Only display numeric IDs
-s, --size            Display total file sizes

查看image 文件

[root@asimov ~]# docker  images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              latest              470671670cac        2 months ago        237MB
centos              7                   5e35e350aded        4 months ago        203MB

使用centos:7镜像启动一个名为asimov_web的容器

[root@asimov ~]# docker  run   --name  asimov_web  centos:7

查看所有容器(正在运行的+没有运行的)

[root@asimov ~]# docker  ps   -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
f7d4f0c3f75b        centos:7            "/bin/bash"         17 seconds ago      Exited (0) 16 seconds ago                       asimov_web

移除名为asimov_web的容器(容器的数据也都会删除)

[root@asimov ~]# docker  rm  asimov_web
asimov_web

移除所有容器

#docker ps -a -q   所有容器id
docker rm $(docker ps -a -q)

将容器80端口映射到服务器的3000端口

[root@asimov ~]# docker  run -p 3000:80   --name  asimov_web  centos:7

-i 以交互模式运行容器 -t: 为容器重新分配一个伪输入终端

[root@asimov ~]# docker  run -p 3000:80   --name  asimov_web   -i  -t  centos:7
[root@24e4e4c517b0 /]# 

exec 在运行的容器中执行命令

[root@asimov ~]# docker  exec -i  -t  asimov_web  /bin/bash

后台运行容器,并返回容器ID

[root@asimov ~]# docker  run   --name  asimov_admin   -d  centos:7 
ca39c042dc650337830be66522ec065d4cf95c060cdb90d0e69df83858b89e42

docker attach 命令连接到运行中的容器或docker exec

nginx官方yum源

[root@24e4e4c517b0 ~]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

安装nginx

[root@24e4e4c517b0 ~]# yum intsall  nginx

启动nginx

[root@24e4e4c517b0 ~]# nginx

查看正在运行的容器

[root@asimov ~]# docker  ps  -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                  NAMES
24e4e4c517b0        centos:7            "/bin/bash"         28 minutes ago      Up 28 minutes       0.0.0.0:3000->80/tcp   asimov_web

在这里插入图片描述
拉取镜像到本地

#以后run的时候都用的本地的镜像
docker pull 镜像name

搜索nginx镜像(也可去docker hub 搜索下载)

docker  search  nginx

在这里插入图片描述

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值