8. Docker 容器

0. 容器配置参数

0.1. 运行模式参数

选项类型说明
-a--attachlist是否绑定到标准输入输出和错误
--entrypointstring镜像存在入口命令时,覆盖为新的命令
--exposelist指定容器暴露出来的端口或端口范围
--group-addlist运行容器的用户组
-i--interactive保持标准输入打开,默认false
--ipcstring容器IPC命名空间,可以为其他容器或主机
--isolationstring容器使用的隔离机制
--log-driverstring指定容器的日志驱动类型
--log-optlist传递给日志驱动的选项
--networkstring指定容器网络模式,包括bridge、none、其他容器内网络、host的网络或某个现有网络等
--network-aliaslist容器在网络中的别名
-P--publish-all通过NAT机制将容器标记暴露的端口自动映射到本地主机的临时端口
-p--publishlist指定如何映射到本地主机端口
--pidstring容器的PID命名空间
--restartstring容器的重启策略,包括no,on-failure[:max-retry]、always、unless-stopped等
--rm容器退出后是否自动删除,不能跟-d同时使用
-t--tty是否分配一个伪终端,默认为false
--tmpfslist挂载临时文件系统到容器
--usernsstring启用userns-remap时配置用户命名空间的模式
--utsstring容器的UTS命名空间
-v--volumelist挂载主机上的文件卷到容器内
--volume-driverstring挂载文件卷的驱动类型
--volumes-fromlist从其他容器挂载卷
-w--workdirstirng容器内的默认工作目录

0.2. 容器环境和参数

选项类型说明
--add-hostlist在容器内添加一个主机名到IP地址的映射关系 hosts
--devicelist映射物理机上的设备到容器内
--dnslist自定义的DNS服务器
--dns-optionlist自定义的DNS选项
--dns-searchlistDNS搜索域
-e--envlist指定容器内环境变量
--env-filelist从文件中读取环境变量到容器内
-h--hostnamestring指定容器内的主机名
--ipstring指定容器的IPv4地址
--ip6string指定容器的IPv6地址
--linklist连接到其他容器
--mac-addressstring指定容器的Mac地址
--namestring指定容器的别名

0.3. 容器资源限制和安全保护参数

选项类型说明
-–blkio-weightuint16容器读写块设备的IO性能权重,默认为0
–-blkio-weight-devicelist指定各个设备的IO性能权重
–-cap-addlist增加容器的linux指定安全能力
–-cap-droplist移除容器的liunux指定安全能力
–-cgroup-parentstring容器cgroups限制的创建路径
–-cidfilestring指定容器进程id号写到的文件
–-cpu-periodint限制容器在CFS调度器下的CPU占用时间片
–-cpu-quotaint限制容器在CFS调度器下CPU配额
–-cpu-rt-periodintLimit CPU real-time period in microseconds
–-cpu-rt-runtimeintLimit CPU real-time runtime in microseconds
-c–-cpu-sharesint允许容器使用的CPU资源的相对权重,默认一个容器能用满一个核的CPU
–-cpusdecimalNumber of CPUs
–-cpuset-cpusstring限制容器能使用哪些CPU核心
–-cpuset-memsstringNUMA架构下使用哪些核心的内存
--device-cgroup-rulelistAdd a rule to the cgroup allowed devices list
–-device-read-bpslist挂载设备的读吞吐率限制 bps
–-device-read-iopslist挂载设备读速率 单位为每秒io次数
–-device-write-bpslist挂载设备的写吞吐率限制 bps
-–device-write-iopslsit挂载设备写速率 单位为每秒io次数
–-kernel-memorystring限制容器内存使用大小
-m–-memorybytes限制容器内应用内存使用大小
–-memory-reservationbytes内存过低时,容器被限制内存的指定值
–-memory-swapbytes限制容器使用内存和交换空间的总大小
-–memory-swappinessint调整容器的内存交换区参数
–-oom-kill-disable内存耗尽时时是否kill容器
-–oom-score-adjintTune host’s OOM preferences (-1000 to 1000)
-–pids-limitint限制容器pid个数
–-privileged是否给容器高权限,容器内应用将不受权限限制
-–read-only是否让容器内文件系统只读
–-security-optlist指定一些安全参数,包括权限,安全能力,apparmor等
-–shm-size=""bytes/dev/shm的大小
--stop-signalstring指定停止容器的系统信号
--stop-timeoutintTimeout (in seconds) to stop a container
--storage-optlistStorage driver options for the container
–-ulimitulimit通过ulimit来限制最大文件数,最大进程数
-u–-userstring指定容器内执行命令的用户信息

0.4. 其他参数

选项类型说明
-l--labellist以键值对方式指定容器的标签信息
--label-filelist从文件中读取标签信息
--disable-content-trustSkip image verification (default true)
--domainnamestringContainer NIS domain name
--gpus gpu-requestGPU devices to add to the container (‘all’ to pass all GPUs)
--health-cmdstringCommand to run to check health
--health-intervaldurationTime between running the check (ms
--health-retriesintConsecutive failures needed to report unhealthy
--health-start-perioddurationStart period for the container to initialize before starting
--health-timeoutdurationMaximum time to allow one check to run (ms
--helpPrint usage
--initRun an init inside the container that forwards signals and reaps processes
--link-local-iplistContainer IPv4/IPv6 link-local addresses
--mountmountAttach a filesystem mount to the container
--no-healthcheckDisable any container-specified HEALTHCHEC
--runtimestringRuntime to use for this container
--sysctlmapSysctl options (default map[])

1. 新建容器 create

docker create [OPTIONS] IMAGE [COMMAND] [ARG...]
Options 查看0.容器配置参数

2. 启动容器 start

docker start [OPTIONS] CONTAINER [CONTAINER...]

选项类型说明
-a--attachAttach STDOUT/STDERR and forward signals
--detach-keysstringOverride the key sequence for detaching a container
-i--interactiveAttach container’s STDIN

3. 新建并启动容器 run

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

4. 查看容器 ps

docker ps [OPTIONS]

选项类型说明
-a--allShow all containers (default shows just running)
-f--filterfilterFilter output based on conditions provided
--formatstringPretty-print containers using a Go template
-n--lastintShow n last created containers (includes all states) (default -1)
-l--latestShow the latest created container (includes all states)
--no-truncDon’t truncate output
-q--quietOnly display numeric IDs
-s--sizeDisplay total file sizes

5. 停止容器 stop

docker stop [OPTIONS] CONTAINER [CONTAINER...]

选项类型说明
-t--timeint杀死前等待停止的秒数 默认10秒

6. 杀死容器 kill

docker kill [OPTIONS] CONTAINER [CONTAINER...]

选项类型说明
-s--signalSignal to send to the container (default “KILL”)

6. 删除容器 rm

docker rm [OPTIONS] CONTAINER [CONTAINER...]

选项类型说明
-f--forceForce the removal of a running container (uses SIGKILL)
-l--linkRemove the specified link
-v--volumesRemove the volumes associated with the container

7.导入导出容器

7.1. 导出容器 export

docker export [OPTIONS] CONTAINER

选项类型说明
-o--outputstringWrite to a file, instead of STDOUT

文件为tar格式

7.2. 导入容器 import

docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]

选项类型说明
-c--changelistApply Dockerfile instruction to the created image
-m--messagestringSet commit message for imported image

7.3. 提交容器 commit

docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

选项类型说明
-a--authorstringAuthor (e.g., “John Hannibal Smith hannibal@a-team.com”)
-c--changelistApply Dockerfile instruction to the created image
-m--messagestringCommit message
-p--pausePause container during commit (default true)

7.4. 载入容器 load

docker load [OPTIONS]

选项类型说明
-i--inputstringRead from tar archive file, instead of STDIN
-q--quietSuppress the load output

8. 进入容器

8.1. exec

docker exec [OPTIONS] Container command

8.2. nsenter

8.3. attach

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值