欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

docker_常用参数

程序员文章站 2022-05-18 09:29:08
...

查看容器 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 文件

[aaa@qq.com ~]# 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的容器

[aaa@qq.com ~]# docker  run   --name  asimov_web  centos:7

查看所有容器(默认正在运行的)

[aaa@qq.com ~]# 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的容器(容器的数据也都会删除)

[aaa@qq.com ~]# docker  rm  asimov_web
asimov_web

移除所有容器

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

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

[aaa@qq.com ~]# docker  run -p 3000:80   --name  asimov_web  centos:7

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

[aaa@qq.com ~]# docker  run -p 3000:80   --name  asimov_web   -i  -t  centos:7
[aaa@qq.com /]# 

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

[aaa@qq.com ~]# docker  exec -i  -t  asimov_web  /bin/bash

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

[aaa@qq.com ~]# docker  run   --name  asimov_admin   -d  centos:7 
ca39c042dc650337830be66522ec065d4cf95c060cdb90d0e69df83858b89e42

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

nginx官方yum源

[aaa@qq.com ~]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

安装nginx

[aaa@qq.com ~]# yum intsall  nginx

启动nginx

[aaa@qq.com ~]# nginx

查看正在运行的容器

[aaa@qq.com ~]# 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

docker_常用参数
拉取镜像到本地

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

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

docker  search  nginx

docker_常用参数

相关标签: docker