动态修改配置用docker update,用法:
docker update -h
Flag shorthand -h has been deprecated, please use --help
Usage: docker update [OPTIONS] CONTAINER [CONTAINER...]
Update configuration of one or more containers
Options:
--blkio-weight uint16 Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
--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 the CPU real-time period in microseconds
--cpu-rt-runtime int Limit the CPU real-time runtime in microseconds
-c, --cpu-shares int CPU shares (relative weight)
--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)
--help Print usage
--kernel-memory string Kernel memory limit
-m, --memory string Memory limit
--memory-reservation string Memory soft limit
--memory-swap string Swap limit equal to memory plus swap: '-1' to enable unlimited swap
--restart string Restart policy to apply when a container exits
1234567891011121314151617181920212223
当前要做的是把一个运行着gitlab 的容器内存限制在2048M以内,尝试用:
docker update -m 2048m gitlab
1
报错:
Memory limit should be smaller than already set memoryswap limit, update the memoryswap at the same time
1
发现问题,docker 默认没有启用memory-swap交换内存,直接设置了内存会出问题,也就是说宿主 swap 支持使用多少则容器即可使用多少,如果 --memory-swap 设置小于 --memory则设置不生效。
将memory-swap 设置值为 -1,表示容器程序使用内存受限,而 swap 空间使用不受限制。
docker update --memory 2048m --memory-swap -1 gitlab
1
问题解决。
Docker复制文件
#查看docker容器列表
docker ps
#进入指定docker容器
docker exec -it 903d6efffdab /bin/bash
#查看当前路径
pwd
#退出容器
exit
#复制文件
docker cp index.jsp 98736920a0d1:/usr/local
#查看实时日志
docker logs -f -t --tail 1000 03b27dc9fb18
#关闭容器
docker stop 03b27dc9fb18