2.0docker环境的各种搭建方法

在centos上安装docker

前提条件

1.移除老版本docker及相关依赖

$ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

2.安装docker所需要的包

$ sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

3.使用如下命令添加稳定的仓库

$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

步骤

1.安装最新版本的docker

$ sudo yum install -y docker-ce docker-ce-cli containerd.io

2.启动docker

$ sudo systemctl start docker

3.为了验证docker是否安装成功,我们启动一个hello world的容器,输出如下信息则证明安装成功。

[root@master2 vagrant]# 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开机自启动,可通过如下命令:

sudo systemctl enable docker

参考

docker官方文档

docker之设置开机自启动(二)

Last updated

Was this helpful?