docker运行环境安装-centos(一)

  在这里我们使用的是docker的社区版Docker CE,针对的是未安装docker的新的主机,如果安装过docker的早期版本,先卸载它们及关联的依赖资源,安装的版本为docker 18.03。

  1、使用yum安装所需的软件包

[origalom@origalom ~]$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2

  2、设置 stable 镜像仓库

[origalom@origalom ~]$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

  3、启用edge 和 testing 镜像仓库

[origalom@origalom ~]$ sudo yum-config-manager --enable docker-ce-edge
[origalom@origalom ~]$ sudo yum-config-manager --enable docker-ce-test
[origalom@origalom ~]$ sudo yum-config-manager --disable docker-ce-edge  # 禁用 

  4、安装最新的CE

[origalom@origalom ~]$ sudo yum install docker-ce

  5、安装指定版本的CE

    在生产环境中,应安装特定版本的CE,而不是每次都使用最新版本。

[origalom@origalom ~]$ yum list docker-ce --showduplicates | sort -r    # 查找可用版本
[origalom@origalom ~]$ sudo yum install docker-ce-<VERSION STRING> # 安装指定版本

  6、启动docker

[origalom@origalom ~]$ sudo systemctl start docker

  7、验证是否安装成功

[origalom@origalom ~]$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:97ce6fa4b6cdc0790cda65fe7290b74cfebd9fa0c9b8c38e979330d547d22ce1
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中文社区

  docker官网

原文地址:https://www.cnblogs.com/origalom/p/8723184.html