ubuntu

来源:互联网 发布:三国讲了什么知乎 编辑:程序博客网 时间:2024/06/05 04:32

前言

由于确实觉得windows下docker以及go的环境配置不爽,特意切换到linux进行go
和docker的学习,今天记录一下docker在ubuntu的中的安装

过程

第一种deb安装包方式

  1. 下载deb https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/

xenial替换为自己的ubuntu版本即可.
或者https://download.docker.com/linux/ubuntu/dists从这个地址在一级级往下选也可以.

2.安装

sudo dpkg -i docker-ce_xxxx~ubuntu_amd64.deb

3.验证

docker –version
Docker version 17.09.0-ce, build afdb6d4(类似的结果)

  1. docker阿里云镜像配置
    打开登陆阿里云镜像官网 https://cr.console.aliyun.com
    然后选择镜像加速器,就有对应的镜像加速地址和加速方式
sudo mkdir -p /etc/dockersudo tee /etc/docker/daemon.json <<-'EOF'{  "registry-mirrors": ["https://pjirpg8s.mirror.aliyuncs.com"]}EOFsudo systemctl daemon-reloadsudo systemctl restart docker

5.运行测试

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 bashShare 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/

第二种在线安装

还可以使用添加repository的方式安装,
1.更新源

sudo apt-get update

2.添加apt的https支持

sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common

3.添加应用的GPG key

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

4.验证key

$ sudo apt-key fingerprint 0EBFCD88

5.添加repository

sudo add-apt-repository \
“deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable”

6.更新源

sudo apt-get update

7.安装

sudo apt-get install docker-ce

8.验证

sudo docker run hello-world

配置

当我们就上述安装完成后,下次启动docker的时候就会出现权限问题。

ot permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.32/containers/create: dial unix /var/run/docker.sock: connect: permission denied.

这是由于我们当前的用户不在docker用户组,导致我们使用的时候每次都需要添加sudo,非常的不方便,接下来配置一下docker用户组。

1.添加docker用户组

sudo groupadd docker

2.将当前的用户添加到docker用户组

sudo gpasswd -a [username] docker
需要把[username]替换为你的用户名

3.重启docker服务

sudo service docker restart

4.切换回话到新的用户组

newgrp - docker

补充

这里官方的文档
https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/#install-docker-ce-1

个人更加喜欢deb的方式,操作简单。
不好的地方就是需要自己手动更新

#

与君共勉!!!