Docker测试环境配置
1、Docker安装
1、pre install
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
2、install
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
3、check
sudo docker run hello-world
2、Docker使用
1、进入容器
docker exec -it c1 /bin/bash #交互式
docker exec -itd c1 /bin/bash #驻留式
sudo docker exec --cpuset-mems 1 --memory="1024m" -p 8088:80 -itd --name sc1 ubuntu:22.04 /bin/bash
2、创建容器
docker run -itd --name slurmhost ubuntu:22.04 /bin/bash
sudo docker run --cpuset-cpus 1 --memory="1024m" -p 8088:80 -itd --name sc1 ubuntu:22.04 /bin/bash
sudo docker run --cpuset-cpus 0 -m "1g" -p 8080:80 -itd --name slurmhost ubuntu:22.04 /bin/bash
3、启动容器
sudo docker start $(sudo docker ps -a | awk '{ print $1}' | tail -n +2)
4、关闭所有容器
sudo docker stop $(sudo docker ps -a | awk '{ print $1}' | tail -n +2)