【Docker】Dockers的安装与初始化

Docker的安装

1、卸载已有的Docker

 sudo apt autoremove docker
 
 sudo apt autoremove docker-engine
 
 sudo apt autoremove docker.io

2、执行自动安装脚本

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

等待很久后安装成功,并出现:

Client: Docker Engine - Community
 Version:           19.03.5
 API version:       1.40
 Go version:        go1.12.12
 Git commit:       XXX
 Built:             Wed Nov 13 07:29:52 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.5
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.12
  Git commit:     XXX
  Built:            Wed Nov 13 07:28:22 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.10
  GitCommit:       XXX
 runc:
  Version:          1.0.0-rc8+dev
  GitCommit:        XXX
 docker-init:
  Version:          0.18.0
  GitCommit:        XXX
If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:

  sudo usermod -aG docker dell

Remember that you will have to log out and back in for this to take effect!

WARNING: Adding a user to the "docker" group will grant the ability to run
         containers which can be used to obtain root privileges on the
         docker host.
         Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
         for more information.

此时,docker CE 的稳定(stable)版本已经安装在系统中。

最后几行提示说,如果想以非root用户使用docker,应该考虑把你当前的用户加入docker组,并且重启终端使其生效,这是因为:

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

使用如下命令建立docker组并将当前用户加入:

sudo groupadd docker
sudo usermod -aG docker 当前用户

3、启动docker

设置docker开机自动启动,并启动docker:

sudo systemctl enable docker
sudo systemctl start docker

(重新加载docker配置、重启docker):

sudo systemctl daemon-reload
sudo systemctl restart docker

验证启动是否成功:

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 run hello-world 的功能是启动一个名称为hello-world的容器,由于初次使用这个命令,且本地不存在hello-world这个镜像,docker会从Docker Hub中pull下来这个镜像,然后运行一个容器实例。具体四步为:

  1. 通过docker客户端连接docker守护进程。
  2. docker守护进程从Docker Hub中pull hello-world镜像。
  3. docker守护进程从拉取的hello-world镜像创建一个新的容器。
  4. docker守护进程将输出传输给docker客户端,客户端再传输到你的终端。

你可能感兴趣的:(DevOps,#,Docker)