修改镜像源 打开终端ssh链接后,首先修改镜像源 ``` vim /etc/docker/daemon.json { "registry-mirrors": [ "https://docker.1panel.live" ] } ``` wq保存退出,重启docker ``` systemctl daemon-reload systemctl restart docker ``` 实验一 1. 拉取progrium/stress压力测试镜像 ``` docker pull progrium/stress ``` 2. 运行容器 ``` docker run -d --name my_stress --cpu-period=100000 --cpu-quota=70000 progrium/stress --cpu 1 ``` 3. 通过top命令验证容器cpu使用率在70% ``` top ``` 4. 进入目录,查看限制值为70000(考点) ``` cd /sys/fs/cgroup/cpu/docker/容器ID/ cat cpu.cfs_quota_us cat cpu.cfs_quota_us cat cpu.cfs_quota_us cat cpu.cfs_quota_us cat cpu.cfs_quota_us ``` 实验二 0.拉取centos镜像 ``` docker pull centos ``` 1. 创建网络 ``` docker network create --driver bridge --subnet 173.18.0.0/16 --gateway 173.18.0.1 my-bridge-network ``` 2. 运行容器1 ``` docker run -d --name centos1 --network my-bridge-network centos:latest /bin/sh -c "while true; do sleep 1; done" ``` 2. 运行容器2 ``` docker run -d --name centos2 --network my-bridge-network centos:latest /bin/sh -c "while true; do sleep 1; done" ``` 3. 进入容器2 ``` docker exec -it centos2 bash ``` 4. ping容器1的ip,多ping几次 ``` ping 173.18.0.2 ``` 5. ping通即可(考点) 实验三 1. 创建一个 Docker volume: ``` docker volume create my_volume ``` 2. 创建并运行一个挂载 volume 的 CentOS 容器 ``` docker run -it --name centos3 -v my_volume:/data centos:latest /bin/bash ``` 3. 在容器中写入文件 ``` echo "this is page from docker managed volume." > /data/index.html ``` 4. 退出容器 ``` exit ``` 5. 删除容器 ``` docker rm -f centos3 ``` 6. 获取 volume 挂载路径 ``` docker volume inspect my_volume ``` 7. 进入路径 ``` cd /var/lib/docker/volumes/my_volume/_data/ ``` 8. 验证文件内容 ``` cat index.html ``` 9. 内容如下即可(考点) ``` this is page from docker managed volume. ```