博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
03:创建容器常用选项
阅读量:6302 次
发布时间:2019-06-22

本文共 9596 字,大约阅读时间需要 31 分钟。

创建容器常用选项:

废话不多说,直接看帮助命令:

[root@localhost ~]# docker container --helpUsage:    docker container COMMANDManage containersCommands:  attach      Attach local standard input, output, and error streams to a running container  commit      Create a new image from a container's changes  cp          Copy files/folders between a container and the local filesystem  create      Create a new container  diff        Inspect changes to files or directories on a container's filesystem  exec        Run a command in a running container  export      Export a container's filesystem as a tar archive  inspect     Display detailed information on one or more containers  kill        Kill one or more running containers  logs        Fetch the logs of a container  ls          List containers  pause       Pause all processes within one or more containers  port        List port mappings or a specific mapping for the container  prune       Remove all stopped containers  rename      Rename a container  restart     Restart one or more containers  rm          Remove one or more containers  run         Run a command in a new container  start       Start one or more stopped containers  stats       Display a live stream of container(s) resource usage statistics  stop        Stop one or more running containers  top         Display the running processes of a container  unpause     Unpause all processes within one or more containers  update      Update configuration of one or more containers  wait        Block until one or more containers stop, then print their exit codesRun 'docker container COMMAND --help' for more information on a command.[root@localhost ~]#

常用的做个截图解释:

来个实例:

# 创建一个后台运行nginxweb的容器,主机名为nginxweb,容器名为nginx_web,主机端口8080映射到容器的80端口,设置环境变量test为123456 [root@localhost ~]# docker container run -itd --name nginx_web -e test=123456 -p 8080:80 -h nginxweb nginxd90c0947c0074f22a3226cc615a4584c6453c75813629b4285a77f5be353767a[root@localhost ~]# docker container ps -lCONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMESd90c0947c007        nginx               "nginx -g 'daemon of…"   7 seconds ago       Up 6 seconds        0.0.0.0:8080->80/tcp   nginx_web[root@localhost ~]# docker logs nginx_web[root@localhost ~]# curl 127.0.0.1:8080Welcome to nginx!

Welcome to nginx!

If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.

For online documentation and support please refer tonginx.org.

Commercial support is available atnginx.com.

Thank you for using nginx.

[root@localhost ~]# docker logs nginx_web172.17.0.1 - - [13/Jan/2019:14:07:27 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"[root@localhost ~]# docker exec -it nginx_web"docker exec" requires at least 2 arguments.See 'docker exec --help'.Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...]Run a command in a running container[root@localhost ~]# docker exec -it nginx_web bashroot@nginxweb:/# hostnamenginxwebroot@nginxweb:/# echo $test123456root@nginxweb:/# exitexit[root@localhost ~]# docker container stop nginx_webnginx_web[root@localhost ~]# docker container ps -lCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESd90c0947c007 nginx "nginx -g 'daemon of…" About a minute ago Exited (0) 4 seconds ago nginx_web[root@localhost ~]# docker container rm d90c0947c007d90c0947c007[root@localhost ~]# docker container ps -lCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES[root@localhost ~]#

 容器资源限制:

 

[root@localhost ~]# docker container run --help |grep cpu      --cpu-period int                 Limit CPU CFS (Completely Fair Scheduler) period      --cpu-quota int                  Limit CPU CFS (Completely Fair Scheduler) quota      --cpu-rt-period int              Limit CPU real-time period in microseconds      --cpu-rt-runtime int             Limit CPU real-time runtime in microseconds  -c, --cpu-shares int                 CPU shares (relative weight)      --cpus decimal                   Number of CPUs      --cpuset-cpus string             CPUs in which to allow execution (0-3, 0,1)      --cpuset-mems string             MEMs in which to allow execution (0-3, 0,1)[root@localhost ~]# docker container run --help |grep memory      --kernel-memory bytes            Kernel memory limit  -m, --memory bytes                   Memory limit      --memory-reservation bytes       Memory soft limit      --memory-swap bytes              Swap limit equal to memory plus swap: '-1' to enable unlimited swap      --memory-swappiness int          Tune container memory swappiness (0 to 100) (default -1)[root@localhost ~]#

 

# memorydocker container run -d --name nginx01 --memory='500m' --memory-swap='600m' --oom-kill-disable nginx# CPUdocker run -d --name nginx02 --cpus='2' nginx# 查看状态:[root@localhost ~]# docker stats nginx01 --no-streamCONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT   MEM %               NET I/O             BLOCK I/O           PIDS7e64017e7e4d        nginx01             0.00%               3.941MiB / 500MiB   0.79%               1.31kB / 0B         7.71MB / 0B         2[root@localhost ~]# docker stats nginx02 --no-streamCONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDSe149218abf8f        nginx02             0.00%               1.375MiB / 1.934GiB   0.07%               656B / 0B           0B / 0B             2[root@localhost ~]#

管理容器常用命令:

  

 

[root@localhost ~]# docker container run -d --name nginx03 -p 8080:80 nginx       # 端口映射[root@localhost ~]# docker container cp anaconda-ks.cfg nginx01:/home/            # cp文件到docker里面[root@localhost ~]# docker container logs nginx01                    #  查看容器日志[root@localhost ~]# docker container logs nginx01172.17.0.1 - - [15/Jan/2019:12:42:58 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"[root@localhost ~]#[root@localhost ~]# docker ps         # 查看活跃中的容器CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMESa326ea3c85dd        nginx               "nginx -g 'daemon of…"   2 minutes ago       Up 2 minutes        0.0.0.0:8080->80/tcp   nginx03e149218abf8f        nginx               "nginx -g 'daemon of…"   15 minutes ago      Up 15 minutes       80/tcp                 nginx027e64017e7e4d        nginx               "nginx -g 'daemon of…"   16 minutes ago      Up 16 minutes       80/tcp                 nginx01[root@localhost ~]# docker top nginx03   # 查看容器的进程UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMDroot                7422                7402                0                   20:44               ?                   00:00:00            nginx: master process nginx -g daemon off;101                 7458                7422                0                   20:44               ?                   00:00:00            nginx: worker process[root@localhost ~]# docker stop nginx01   # 停止容器nginx01[root@localhost ~]# docker ps CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMESa326ea3c85dd        nginx               "nginx -g 'daemon of…"   2 minutes ago       Up 2 minutes        0.0.0.0:8080->80/tcp   nginx03e149218abf8f        nginx               "nginx -g 'daemon of…"   16 minutes ago      Up 16 minutes       80/tcp                 nginx02[root@localhost ~]# docker ps -a    # 查看所有容器CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS                  NAMESa326ea3c85dd        nginx               "nginx -g 'daemon of…"   2 minutes ago       Up 2 minutes                0.0.0.0:8080->80/tcp   nginx03e149218abf8f        nginx               "nginx -g 'daemon of…"   16 minutes ago      Up 16 minutes               80/tcp                 nginx027e64017e7e4d        nginx               "nginx -g 'daemon of…"   17 minutes ago      Exited (0) 10 seconds ago                          nginx01[root@localhost ~]# docker start nginx01    # 启动容器nginx01[root@localhost ~]# docker ps CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMESa326ea3c85dd        nginx               "nginx -g 'daemon of…"   3 minutes ago       Up 3 minutes        0.0.0.0:8080->80/tcp   nginx03e149218abf8f        nginx               "nginx -g 'daemon of…"   16 minutes ago      Up 16 minutes       80/tcp                 nginx027e64017e7e4d        nginx               "nginx -g 'daemon of…"   17 minutes ago      Up 5 seconds        80/tcp                 nginx01[root@localhost ~]# docker stop nginx01nginx01[root@localhost ~]# docker rm nginx01  # 删除容器nginx01[root@localhost ~]# docker ps -aCONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMESa326ea3c85dd        nginx               "nginx -g 'daemon of…"   3 minutes ago       Up 3 minutes        0.0.0.0:8080->80/tcp   nginx03e149218abf8f        nginx               "nginx -g 'daemon of…"   17 minutes ago      Up 16 minutes       80/tcp                 nginx02[root@localhost ~]#

 

转载于:https://www.cnblogs.com/zheng-weimin/p/10264283.html

你可能感兴趣的文章
Redis 单key值过大 优化方式
查看>>
【数据库】表分区
查看>>
nutz-sqltpl 1.3.4.RELEASE 发布,在 Nutz 项目中“解决 Java 拼接 SQL”问题
查看>>
城市 | 800个地铁站数据透析的京沪白领图鉴:隐形土豪、无产中产阶级和猪猪女孩...
查看>>
前端脚本!网站图片素材中文转英文
查看>>
linux的常用易忘命令
查看>>
PHP 分割字符串
查看>>
java 基于QRCode、zxing 的二维码生成与解析
查看>>
关于职业规划的一些思考
查看>>
img垂直水平居中与div
查看>>
Fabrik – 在浏览器中协作构建,可视化,设计神经网络
查看>>
防恶意注册的思考
查看>>
http2-head compression
查看>>
C# 命名空间
查看>>
订餐系统之同步美团商家订单
查看>>
使用ArrayList时设置初始容量的重要性
查看>>
Java Web-----JSP与Servlet(一)
查看>>
Maven搭建SpringMVC+Mybatis项目详解
查看>>
关于量子理论:最初无意的简化,和一些人有意的强化和放大
查看>>
CentOS 6.9通过RPM安装EPEL源(http://dl.fedoraproject.org)
查看>>