Docker学习笔记 ->环境与背景篇->3、安装docker(ubuntu )

ubuntu 18.0.4安装安装docker

ubuntu 版本 18.04

安装步骤命令:
sudo snap install docker # 但这种仅限个人使用,类似于conda

启动和关闭docker

启动docker
sudo service docker start
关闭Docker服务
sudo service docker stop

安装完之后可能会出现启动失败,解决方案如下

执行sudo service docker start失败,提示Failed to start docker.service: Unit docker.service is masked.
输入以下命令解决
systemctl unmask docker.service
systemctl unmask docker.socket
systemctl start docker.service

权限管理,默认docker运行需要sudo权限,需要配置用户为docker组才可以使用docker。通常只应把信任的用户加入docker用户组因为docker用户组的权限相当于root。这样处理之后就不用在使用sudo来执行docker命令了。

增加一个用户组docker
sudo groupadd docker
把用户${USER}加入docker用户组
USER=yx
sudo usermod -aG docker ${USER}

重启docker服务(可不执行)

sudo service docker restart

有报错信息如下:

# Job for docker.service failed because the control process exited with error code.
# See "systemctl status docker.service" and "journalctl -xe" for details.

解决方案:

输入systemctl status docker.service查看具体的错误原因
docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since 三 2016-10-19 02:58:23 UTC; 20s ago
     Docs: http://docs.docker.com
  Process: 10835 ExecStart=/usr/bin/docker-current daemon --exec-opt native.cgroupdriver=systemd $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY (code=exited, status=1/FAILURE)
 Main PID: 10835 (code=exited, status=1/FAILURE)


10月 19 02:58:23 ip-172-31-8-236.cn-north-1.compute.internal systemd[1]: Starting Docker Application Container Engine...
10月 19 02:58:23 ip-172-31-8-236.cn-north-1.compute.internal docker-current[10835]: time="2016-10-19T02:58:23.880006578Z" level=fatal msg="can't create unix socket /var/run/docker.sock: is a directory"
10月 19 02:58:23 ip-172-31-8-236.cn-north-1.compute.internal systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
10月 19 02:58:23 ip-172-31-8-236.cn-north-1.compute.internal systemd[1]: Failed to start Docker Application Container Engine.
10月 19 02:58:23 ip-172-31-8-236.cn-north-1.compute.internal systemd[1]: Unit docker.service entered failed state.
10月 19 02:58:23 ip-172-31-8-236.cn-north-1.compute.internal systemd[1]: docker.service failed.

/var/run/docker.sock是一个目录,导致docker启动失败

解决过程:

删除docker.sock目录,

service docker start 启动docker服务

失败原因可能还会出现找不到指定的目录,按照错误原因使用命令创建相应的目录既可以解决。

你可能感兴趣的:(安装docker(ubuntu,),Docker,Docker入门与实践)