- 安装docker
- 卸载旧版docker
旧版本的Docker被称作docker或者docker-engine,Docker CE(社区版)包现在被叫做docker-ce。如果之前安装过了,需要先卸载:
sudo apt-get remove docker docker-engine docker.io
- 添加新的docker存储库
# 更新apt安装包索引 sudo apt-get update # 安装软件包以允许apt通过HTTPS使用存储库 sudo apt-get install -y\ apt-transport-https \ ca-certificates \ curl \ software-properties-common # 添加Docker官方的GPG密钥 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - # 确保现在系统已经拥有密钥指纹的后八个字符串:9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 输入指令: sudo apt-key fingerprint 0EBFCD88 # 安装稳定版仓库 sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
- 安装docker-ce
sudo apt-get update sudo apt-get install -y docker-ce # 如果不想安装最新版的Docker,可以先查看可安装版本: # apt-cache madison docker-ce # 查找到相应的docker版本号 # sudo apt-get install docker-ce=<VERSION>
-
验证安装
sudo docker run hello-world
这个命令下载一个测试图像并在容器中运行。容器运行时,会打印一条信息消息并退出。
Notice:这个时候可能会出现无法连接的情况,这是由于国内访问Docker Hub不稳定。我们可以注册一个阿里云账户,获得一个专属免费的加速器地址(传送门)。然后运用下面的命令配置我们的镜像加速器:# 也可以在.docker中 # mkdir ~/.docker # vim ~/.docker sudo mkdir -p /etc/docker sudo vim /etc/docker/daemon.json
a 将以下内容写入文本:
{ "registry-mirrors": ["自己的镜像地址"] }
b 输入以下命令后注销并重新登录:
sudo systemctl daemon-reload sudo systemctl restart docker
c 再次运行hello-world:
sudo docker run hello-world
d 若出现以下信息则表明安装成功:
Unable to find image 'hello- world:latest' locally latest: Pulling from library/hello-world ca4f61b1923c: Pull complete Digest:sha256:66ef312bbac49c39a89aa9bcc3cb4f3c9e7de3788c944158df3ee0176d32b751 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) 1. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 2. 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://cloud.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/
e 检查版本信息:
sudo docker version
显示信息如下:
Client: Version: 17.12.0-ce API version: 1.35 Go version: go1.9.2 Git commit: c97c6d6 Built: Wed Dec 27 20:11:19 2017 OS/Arch: linux/amd64 Server: Engine: Version: 17.12.0-ce API version: 1.35 (minimum version 1.12) Go version: go1.9.2 Git commit: c97c6d6 Built: Wed Dec 27 20:09:53 2017 OS/Arch: linux/amd64 Experimental: false
-
docker使用普通用户运行,需要将用户加入docker组中, 重启docker
将一个已有用户 username 增加到一个已有用户组 docker 中,使此用户组成为该用户的附加用户组,可以使用带 -a 参数的 usermod 指令。-a 代表 append, 也就是将用户添加到新用户组中而不必离开原有的其他用户组。不过需要与 -G 选项配合使用:sudo usermod -a -G docker username
a 如果要同时将 username 的主要用户组改为 docker,则直接使用 -g 选项:
usermod -g docker username
b 重启docker
sudo service docker restart
- 卸载旧版docker
- docker-compose安装
- 下载最新的额docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
- 更改二进制文件权限,使其能够运行
sudo chmod +x /usr/local/bin/docker-compose
- 测试安装
docker-compose --version
ubuntu下安装配置docker
最新推荐文章于 2024-07-30 19:42:40 发布