Docker CE 学习笔记2 : Docker 安装后的步骤

目录

1、 以非 root 用户管理 Docker 

2、配置Docker 在系统启动时运行

3、使用不同的存储引擎

4、配置Docker守护进程侦听连接的位置

 4.1  配置远程访问使用systemd单元文件


参考:https://docs.docker.com/install/linux/linux-postinstall/

本节包含可选的过程,用于配置Linux主机以更好地使用Docker。

1、 以非 root 用户管理 Docker 

Docker守护进程绑定到Unix套接字而不是TCP端口。默认情况下,Unix套接字root 用户拥有,其他用户只能使用sudo访问它。Docker守护进程始终作为根用户运行。

如果不想用sudo作为docker命令的序言,可以创建一个名为docker的Unix组并将用户添加到其中。当Docker守护进程启动时,它创建一个可由Docker组成员访问的Unix套接字。

注意:docker组授予等同于root用户的特权。有关这如何影响系统安全性的详细信息,请参见 Docker Daemon Attack Surface..

创建一个docker 用户组,并添加到你的用户当中.

 groupadd docker
 usermod -aG docker yulei

注销并重新登录,以便重新评估您的组成员资格。 如果在虚拟机上进行测试,可能需要重启虚拟机以使更改生效。在桌面Linux环境(如X Windows)上,完全退出会话,然后重新登录。

验证您可以在没有sudo的情况下运行docker命令,这个命令下载一个测试映像并在容器中运行它。当容器运行时,它打印一条信息消息并退出。

[yulei@namenode1 ~]$ 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/

2、配置Docker 在系统启动时运行

$ sudo systemctl enable docker

3、使用不同的存储引擎

有关不同存储引擎的信息,请参见Storage drivers。默认存储引擎和受支持的存储引擎列表取决于主机的Linux发行版和可用的内核驱动程序。

4、配置Docker守护进程侦听连接的位置

默认情况下,Docker守护进程侦听UNIX套接字上的连接,以接受来自本地客户机的请求。通过将Docker配置为监听IP地址和端口以及UNIX套接字,可以允许Docker接受来自远程主机的请求。有关此配置选项的更详细信息,请参阅Docker CLI Reference文章的 “将Docker绑定到另一个主机/端口或unix套接字”部分。

  •   Docker EE customers

     Docker EE客户可以通过UCP客户机包获得对UCP的远程CLI访问。UCP客户端包由UCP生成,并由相互的TLS保护。有关更多信息,       请参阅关于UCP的CLI access的文档。

  •   Secure your connection

       在配置Docker以接受来自远程主机的连接之前,理解将Docker打开到网络的安全含义是至关重要的。如果不采取步骤保护连接,则远      程非根用户可能获得主机上的根访问权。有关如何使用TLS证书来保护此连接的更多信息,请参阅本文中关于如何保护Docker守护进程     套接字的内容。

      可以使用Docker配置Docker来接受远程连接。docker.service 系统单元文件,用于使用systemd的Linux发行版,例如RedHat、           CentOS、Ubuntu和SLES的最新版本,或者使用daemon.json 文件,推荐用于不使用systemd的Linux发行版。

  • systemd vs daemon.json

     同时使用systemd 单元文件和daemon.json 文件 配置Docker 监听连接 会引起一个冲突来阻止Docker 启动.

 4.1  配置远程访问使用systemd单元文件

  1. Use the command sudo systemctl edit docker.service to open an override file for docker.service in a text editor.

  2. Add or modify the following lines, substituting your own values.

    [Service]
    ExecStart=
    ExecStart=/usr/bin/dockerd -H fd:// -H tcp://127.0.0.1:2375
    
  3. Save the file.

  4. Reload the systemctl configuration.

     $ sudo systemctl daemon-reload
    
  5. Restart Docker.

    $ sudo systemctl restart docker.service
    
  6. Check to see whether the change was honored by reviewing the output of netstat to confirm dockerd is listening on the configured port.

    $ sudo netstat -lntp | grep dockerd
    tcp        0      0 127.0.0.1:2375          0.0.0.0:*               LISTEN      3758/dockerd

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值