目录
1.centos安装docker
1.1卸载旧版本的docker
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
1.2添加仓库文件(不适用docker官方源,使用阿里云镜像)
yum install -y yum-utils
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
1.3安装docker
yum install docker-ce docker-ce-cli containerd.io -y
1.4启动docker,并设置为开机自启
systemctl start docker
systemctl enable docker
1.5测试
输入指令测试,显示如下说明docker安装成功
docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:f861ba8563637d693e3043069b0a4ebf3d92c2e865b541379f6a6b8164b7c8bb
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
The Docker client contacted the Docker daemon.
The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
2.ubuntu安装docker
2.1卸载旧版本docker
sudo apt-get remove docker docker-engine docker.io containerd runc
2.2更新系统所有能更新的软件
sudo apt-get update
2.3添加仓库
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release -y
2.4添加官方GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
设置稳定仓库
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
2.5安装docker
先更新软件再安装docker
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io -y
#ubuntu安装完docker会自动启动docker
2.6验证
sudo docker run hello-world