Ubuntu 下安装Docker小结

这几天一直在折腾ubuntu下安装docker——webRTC service 需要在Docker环境下才能运行,网上的资料有的是存在问题的,会受限于当前ubuntu的版本。本人的ubuntu版本为:

uname -r

Linux server 3.16.0-30-generic #40~14.04.1-Ubuntu SMP Thu Jan 15 17:43:14 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

在安装了最新的docker,之后一直出问题。

docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: 
starting container process caused "process_linux.go:297: 
copying bootstrap data to pipe caused \"write init-p: broken pipe\"": unknown.

看了帖子说是ubuntu版本过低,需要升级ubuntu版本。shit,我就安装个工具你让我更新系统版本?结果很多帖子都说是系统版本太低,无法使用当前版本的docker。能不能将docker版本降低?

sudo apt-cache madison docker-ce

 docker-ce | 18.06.3~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu/ trusty/stable amd64 Packages
 docker-ce | 18.06.2~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu/ trusty/stable amd64 Packages
 docker-ce | 18.06.1~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu/ trusty/stable amd64 Packages
 docker-ce | 18.06.0~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu/ trusty/stable amd64 Packages
 docker-ce | 18.03.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu/ trusty/stable amd64 Packages
 docker-ce | 18.03.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu/ trusty/stable amd64 Packages
 docker-ce | 17.12.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu/ trusty/stable amd64 Packages
 docker-ce | 17.12.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu/ trusty/stable amd64 Packages
 docker-ce | 17.09.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu/ trusty/stable amd64 Packages
 docker-ce | 17.09.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu/ trusty/stable amd64 Packages
 docker-ce | 17.06.2~ce-0~ubuntu | https://download.docker.com/linux/ubuntu/ trusty/stable amd64 Packages
 docker-ce | 17.06.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu/ trusty/stable amd64 Packages
 docker-ce | 17.06.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu/ trusty/stable amd64 Packages
 docker-ce | 17.03.2~ce-0~ubuntu-trusty | https://download.docker.com/linux/ubuntu/ trusty/stable amd64 Packages
 docker-ce | 17.03.1~ce-0~ubuntu-trusty | https://download.docker.com/linux/ubuntu/ trusty/stable amd64 Packages
 docker-ce | 17.03.0~ce-0~ubuntu-trusty | https://download.docker.com/linux/ubuntu/ trusty/stable amd64 Packages

我选择的是 17.12.1~ce-0~ubuntu

贴上完整操作步骤(前面一部分是第一次安装docker时的命令)

第一部分

1.更新Ubuntu的apt源索引

$ sudo apt-get update
2.安装包允许apt通过HTTPS使用仓库

$ sudo dpkg --configure -a
$ sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
3.添加Docker官方GPG key


$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

4.设置Docker稳定版仓库

$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
5.更新apt源索引


$ sudo apt-get update
6.安装最新版本Docker CE(社区版)

$ sudo apt-get install docker-ce

查看安装Docker的版本

$ docker --version
检查Docker CE 是否安装正确

$ sudo docker run hello-world

到此会因为docker版本过高导致无法运行hello-world

因此第二部分的步骤为:

卸载docker-ce
sudo apt-get autoremove docker-ce
显示稳定可使用版本
sudo apt-cache madison docker-ce
安装稳定版本
sudo apt-get install docker-ce=17.12.1~ce-0~ubuntu

成功后再运行:sudo 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/

至此,docker安装成功,版本为:Docker version 17.12.1-ce, build 7390fc6

最后贴上基本的docker指令

# 启动docker
sudo service docker start

# 停止docker
sudo service docker stop

# 重启docker
sudo service docker restart

# 列出镜像
docker image ls

# 拉取镜像
docker image pull library/hello-world

# 删除镜像
docker image rm 镜像id/镜像ID

# 创建容器
docker run [选项参数] 镜像名 [命令]

# 停止一个已经在运行的容器
docker container stop 容器名或容器id

# 启动一个已经停止的容器
docker container start 容器名或容器id

# kill掉一个已经在运行的容器
docker container kill 容器名或容器id

# 删除容器
docker container rm 容器名或容器id

你可能感兴趣的:(docker)