FAIRYFAR-INTERNAL
 
  FAIRYFAR-INTERNAL  |  SITEMAP  |  ABOUT-ME  |  HOME  
docker安装方法及使用示例

一、安装docker

从阿里云yum源安装依赖库

  • libseccomp-2.3.1-4.el7.x86_64
  • container-selinux-2.119.1-1.c57a6f9.el7.noarch
snippet.bash
[root@localhost software]# yum install libseccomp.x86_64
[root@localhost software]# yum install container-selinux.noarch

下载组件

安装组件

snippet.bash
[root@localhost software]# rpm -i ./containerd.io-1.2.6-3.3.el7.x86_64.rpm
[root@localhost software]# rpm -i ./docker-ce-cli-19.03.9-3.el7.x86_64.rpm
[root@localhost software]# rpm -i ./docker-ce-19.03.9-3.el7.x86_64.rpm

二、启动docker服务

snippet.bash
[root@localhost software]# systemctl start docker

三、安装CentOS示例

搜索镜像

snippet.bash
[root@localhost software]# docker search CentOS
NAME         DESCRIPTION                          STARS     OFFICIAL   AUTOMATED
centos       The official build of CentOS.        6029       [OK]                
ansible/centos7-ansible   Ansible on Centos7      129        [OK]
……

安装CentOS镜像

CentOS镜像获取地址:https://hub.docker.com/_/centos?tab=tags

snippet.bash
[root@localhost software]# docker pull centos:centos7
centos7: Pulling from library/centos
524b0c1e57f8: Pull complete 
……

查询已安装的镜像

snippet.bash
[root@localhost software]# docker images 
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              centos7             b5b4d78bc90c        4 weeks ago         203MB

run镜像

snippet.bash
[root@localhost software]# docker run -itd --name centos-node1 centos:centos7
4c619a88c1eb3a546e53858826a71daf80a8fc41fae17d53c67c80f671e71f2a
  • -i: 以交互模式运行容器,通常与 -t 同时使用;
  • -t: 为容器重新分配一个伪输入终端,通常与 -i 同时使用;
  • -d: 后台运行容器,并返回容器ID;

查询run的镜像

snippet.bash
[root@localhost software]# docker ps
CONTAINER ID  IMAGE           COMMAND      CREATED         STATUS        PORTS   NAMES
4c619a88c1eb  centos:centos7  "/bin/bash"  7 seconds ago   Up 7 seconds          centos-node1

执行命令

通过 exec 命令对指定的容器执行 bash:

snippet.bash
[root@localhost software]# docker exec -it centos-node1 /bin/bash


打赏作者以资鼓励: