Dokcer安装,用户配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chushoutaizhong/article/details/82992303

Ubuntu安装docker


curl -fsSL get.docker.com -o get-docker.sh
sudo sh get-docker.sh --mirror Aliyun
启动 Docker CE
sudo service docker start


centos安装docker


curl -fsSL get.docker.com -o get-docker.sh
sudo sh get-docker.sh --mirror Aliyun
启动 Docker CE
sudo systemctl enable docker
sudo systemctl start docker

使用脚本安装亲测可以使用 离线安装没有实践也就不贴了

建立docker用户组

默认情况下, docker命令会使用Unix socket 与Docker引擎通讯。而只有root用户和docker组的用户才可以访问Docker引擎的
Unix socket。出于安全考虑,一般 Linux 系统 上不会直接使用  root 用户。因此,更好地做法是将需要使用 docker 的用户加
入 docker用户组。


建立 docker组:


sudo groupadd docker
将当前用户加入docker组:
sudo usermod -aG docker $USER
更新用户组 必须不然不起作用
newgrp docker
退出当前终端并重新登录,进行如下测试。


测试 Docker是否安装正确

输入命令
docker run hello-world

Unable    to    find    image    'hello-world:latest'    locally
latest:    Pulling    from    library/hello-world
ca4f61b1923c:    Pull    complete
Digest:    sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c
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)
    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://cloud.docker.com/
For    more    examples    and    ideas,    visit:
    https://docs.docker.com/engine/userguide/
若能正常输出以上信息,则说明安装成功。

镜像加速器


国内从 Docker Hub 拉取镜像有时会遇到困难,此时可以配置镜像加速器。Docker 官方和国
内很多云服务商都提供了国内加速器服务

Ubuntu 14.04、Debian 7 Wheezy
对于使用upstart的系统而言,编辑 /etc/default/docker 文件,在其中的DOCKER_OPTS中
添加获得的加速器配置:
DOCKER_OPTS="--registry-mirror=https://registry.docker-cn.com"
重新启动服务。
sudo  service docker restart


Ubuntu 16.04+、Debian 8+、CentOS 7
对于使用 systemd 的系统,请在/etc/docker/daemon.json 中写入如下内容(如果文件不存在请新建该文件)
{
  "registry-mirrors": [
    "https://registry.docker-cn.com"
  ]
}
注意,一定要保证该文件符合 json  规范,否则 Docker 将不能启动。
之后重新启动服务。
sudo  systemctl  daemon-reload
sudo  systemctl  restart docker

参考 <<docker-从入门到实践>>

猜你喜欢

转载自blog.csdn.net/chushoutaizhong/article/details/82992303