• 42 【docker】run命令


    最常用的两个option是,网络端口映射,和文件共享

    最基本的启动命令(从image创建一个container并启动):docker run -d <image-name>

    -d:表示守护进程方式启动

    -v:本地host的文件(文件夹)映射到容器内的文件(文件夹)

    想起的-v参数是:-v [[host-dir:] container-dir [:OPTIONS]]

    -v的第一个参数是host-dir,这个参数是可选参数,如果没设置,docker会在host主机中创建该文件夹

    第二个参数是container-dir,这个参数是必选参数,是容器内部的文件夹

    第三个参数是OPTIONS,有几种选项:

    [rw|ro],读写或者只读

    [z|Z],不太了解(这里是为了适应需要有标签的OS-SElinux系统的,z表示和宿主机共享标签,Z表示container是私有标签)

    [[r]shared|[r]slave|[r]private],不太了解,(默认是[r]private,docker内部对共享的dir的操作,在host主机上是不可见的;[r]shared,host和container上的修改都是共享的,双方的修改对于对方都可见;[r]slave,表明host上做的修改在container是可见的,但是container上的改动,host上是不可见的)

    [nocopy],不允许container中,从其他文件夹下拷贝文件到该文件夹下

    -p:端口映射

    贴一下man原文

           -p, --publish=[]
              Publish a container's port, or range of ports, to the host.
    
           Format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort Both hostPort and containerPort can be specified as a range of ports.  When
           specifying ranges for both, the number of container ports in the range must match the number of host ports in the range.  (e.g., docker run -p 1234-1236:1222-1224 --name thisWorks
           -t busybox but not docker run -p 1230-1236:1230-1240 --name RangeContainerPortsBiggerThanRangeHostPorts -t busybox) With ip: docker run -p 127.0.0.1:$HOSTPORT:$CONTAINERPORT
           --name CONTAINER -t someimage Use docker port to see the actual mapping: docker port CONTAINER $CONTAINERPORT

    -p选项,把container中的端口或者一段端口发布到主机上

    格式如下:ip:hostPort:containerPort  | ip::containerPort | hostPort:containerPort | containerPort

    格式1:把containerPort发布到ip:hostPort(原因是有的host是多个IP的,这个命令可以指定发布到一个ip上)

    格式2:ip::containerPort(和格式1类似,不过hostPort和containerPort一致时可以不用再写hostPort)

    格式3:hostPort:containerPort(主机是单个IP时,不用再额外指定ip,直接使用hostPort+containerPort即可)

    格式4:containerPort(主机IP单一,并且hostPort=containerPort时,可以忽略hostPort)

  • 相关阅读:
    基于Servlet+JSP+JavaBean开发
    jsp&servlet报红线javax.servlet.jsp.XXXX cannot be resolved to a type类似错误解决办法
    java为什么要定义接口等相关解释
    SpringMVC的注解方式
    MyBatis映射
    hibernate、JDBC 实现 oracle ID 的自动增加 功能
    SSH框架的JSP网站添加数据为什么没反应
    又考完一科 又过完一年
    一个招标书文件的需求分析
    《需求分析》读后感之二
  • 原文地址:https://www.cnblogs.com/helww/p/10121116.html
Copyright © 2020-2023  润新知