Ubuntu-16-04-安装配置Docker
安装相关包 $ sudo apt-get update # 先更新一下软件源库信息 $ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ software-properties-common 添加软件仓库 官方仓库 # 添加 Docker 官方的 GPG 密钥(为了确认所下载
目录8 个章节
安装相关包
$ sudo apt-get update # 先更新一下软件源库信息
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
添加软件仓库
官方仓库
# 添加 Docker 官方的 GPG 密钥(为了确认所下载软件包的合法性,需要添加软件源的 GPG 密钥)
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# 设置稳定版本的apt仓库地址
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
阿里云仓库
$ curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
$(lsb_release -cs) \
stable"
安装docker
$ sudo apt-get update
$ sudo apt-get install docker-ce # 安装最新版的docker
如果需要安装指定版本的,使用以下命令:
$ apt-cache policy docker-ce # 查看可供安装的所有docker版本
$ sudo apt-get install docker-ce=18.03.0~ce-0~ubuntu # 安装指定版本的docker
``
# 检查docker是否安装成功
$ docker --version # 查看安装的docker版本
添加访问权限
这个时候运行docker的话,如果不是root用户会报错:
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.26/images/json: dial unix /var/run/docker.sock: connect: permission denied
看一下权限
$ cd /var/run
$ ll | grep docker
# 输出如下
drwx------ 8 root root 180 11月 21 16:36 docker
-rw-r--r-- 1 root root 5 11月 21 16:35 docker.pid
srw-rw---- 1 root docker 0 11月 21 16:35 docker.sock
可以看到 docker.sock 的所有者是 docker 这个组。所以我们要把当前用户添加到这个组里。
$ sudo gpasswd -a ${USER} docker
重启docker
sudo service docker restart
切换当前会话到新 group 或者重启 X 会话
newgrp - docker
注意:最后一步是必须的,否则因为 groups 命令获取到的是缓存的组信息,刚添加的组信息未能生效,所以 docker images 执行时同样有错。
运行docker测试
这个时候就可以运行helloworld测试啦~
$ docker run hello-world
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/
到这里就安装完成了~
参考资料
https://docs.docker.com/get-started/#test-docker-version https://www.jianshu.com/p/a12558da034e https://www.jianshu.com/p/95e397570896
_EOF_
Ubuntu-16-04-安装配置Docker
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
在Nginx上配置https加密服务器
前言 最近开发微信小程序需要使用Https,于是折腾了一番。 超简单步骤 1. 申请SSL证书 一般云服务器提供商就会提供这种服务,我在腾讯云上申请了,十分钟就完成了。 2. 上传证书 上传到一个文件夹里面 3. 配置nginx 网络上的资料都是直接修改 /etc/nginx/nginx.conf 这个文件。 不过我的服务器上这个文件里头没有 server 这个节点可以配置。 因此需要修改 /et
2025-10-27 · 系统配置 · 约 1 分钟
Linux--使用Snap安装第三方微信客户端Electronic-Wechat
前言 腾讯估计是不会给Linux系统开发任何软件了,不过问题不大。我们有很多好用的第三方软件替代~~(无奈之举,摊手)~~ 关于Snap Ubuntu官网上的介绍 Snaps are applications packaged with all their dependencies to run on all popular Linux distributions from a single bu
2025-10-27 · 系统配置 · 约 1 分钟
配置MariaDB数据库服务端远程访问
操作步骤 开启远程访问权限 连接MariaDB数据库,执行以下命令开启远程访问。 grant all privileges on *.* to 'root'@'192.168.248.248' identified by 'password'; flush privileges; 如果需要任意IP地址访问,就把IP地址换成%。 修改配置文件 在网络上能搜索到的资料都只说了第一点,然而亲测之后并没有
2025-10-27 · 系统配置 · 约 1 分钟
小心误关了NAS服务器!修改Linux的电源键功能
NAS居然离线关机了?电源键被傻逼系统接管了。改改`logind.conf`让这玩意忽略电源键,省得误操作重启关机。谁用谁知道,别真当NAS是玩具。
2025-10-27 · 系统配置 · 约 1 分钟
讨论
共 0 条加载评论中…