Ubuntu安装docker
Ubuntu安装docker
1、先卸载旧版,如果没有的话,就不用执行了,直接第二步。
apt-get remove docker docker-engine docker.io containerd runc
2、在终端输入
apt update
apt-get install ca-certificates curl gnupg lsb-release
3、安装证书
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
4、写入软件源信息
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
5、安装
sudo apt-get install docker-ce docker-ce-cli containerd.io
中途出现问题的话,使用 sudo apt-get update 试试
另外一种安装方式:
# 下载docker 17.09.0版本【必须使用此版本】
curl -O https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/docker-ce_17.09.0~ce-0~ubuntu_amd64.deb
# 安装docker
sudo dpkg -i docker-ce_17.09.0~ce-0~ubuntu_amd64.deb
# 安装依赖
sudo apt -y -f install
# 修改docker权限(非必须)
sudo usermod -aG docker $USER
6、启动docker
systemctl start docker
WSL 中暂时不支持 systemctl,所以使用上面的命令会报错。
sudo systemctl报错信息为System has not been booted with systemd as init system (PID 1). Can't operate.Failed to connect to bus: Host is down
WSL使用如下步骤
# 安装cgroupfs-mount
sudo apt -y install cgroupfs-mount
# 以管理员身份启动WSL控制台,执行以下命令启动docker
# 需要注意的是每次电脑重启后先执行cgroupfs-mount再启动docker服务。
sudo cgroupfs-mount
sudo service docker start
7、测试Docker
# 测试安装结果
$ docker version
Client:
Version: 17.09.0-ce
API version: 1.32
Go version: go1.8.3
Git commit: afdb6d4
Built: Tue Sep 26 22:42:18 2017
OS/Arch: linux/amd64
Server:
Version: 17.09.0-ce
API version: 1.32 (minimum version 1.12)
Go version: go1.8.3
Git commit: afdb6d4
Built: Tue Sep 26 22:40:56 2017
OS/Arch: linux/amd64
Experimental: false
# 测试运行容器
$ docker run --rm hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete Digest: sha256:92695bc579f31df7a63da6922075d0666e565ceccad16b59c3374d2cf4e8e50e
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:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. 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/
8、配置
docker开启远程访问
# 默认情况下,Docker守护进程Unix socket(/var/run/docker.sock)来进行本地进程通信,而不会监听任何端口,
# 因此只能在本地使用docker客户端或者使用Docker API进行操作。如果想在其他主机上操作Docker主机,
# 就需要让Docker守护进程打开一个HTTP Socket,这样才能实现远程通信。
# 编辑docker的配置文件/etc/default/docker修改DOCKER_OPTS
# 同时监听本地unix socket和远程http socket(2375)
DOCKER_OPTS="-H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375"
# 然后重新启动docker守护进程。
sudo service docker restart
# 此时发现docker守护进程已经在监听2375端口,在另一台主机上可以通过该端口访问Docker进程了。
docker -H IP:2375 images
# 本地操作docker。
docker images
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具