Centos 7 快速安装 Docker

安装 Docker

[root@localhost~]# yum install docker


启动 docker 服务

[root@localhost~]# systemctl start docker.service

[root@localhost~]# systemctl enable docker.service


安装 centos 镜像

[root@localhost~]# docker pull centos

Using default tag: latest
Trying to pull repository docker.io/library/centos ...

latest: Pulling from docker.io/library/centos

6bbedd9b76a4: Downloading 2.531 MB/49.87 MB

fc19d60a83f1: Download complete

de413bb911fd: Download complete

2879a7ad3144: Download complete

668604fde02e: Download complete

668604fde02e: Pulling fs layer*

检查 centos 镜像安装状态

[root@localhost~]# docker images centos

REPOSITORY          TAG                IMAGE ID            CREATED            SIZE

docker.io/centos    latest              980e0e4c79ec        7 weeks ago         196.7 MB

运行一个新的容器

[root@localhost~]# docker run -i -t centos /bin/bash

[root@bd1a482d44f5 /]#

参数解释
-i, --interactive               Keep STDIN open even if not attached

-t, --tty                            Allocate a pseudo-TTY

PS:“[root@bd1a482d44f5 /]#” 这行出现证明已进入容器

退出容器

[root@localhost~]# exit

exit

查看运行的容器

[root@localhost~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
48a415dde98a        centos              "/bin/bash"         2 hours ago         Up 2 hours                              nauseous_ardinghelli

查看全部容器列表

[root@localhost~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
bd7d9471fff8        ubuntu              "/bin/bash"         7 minutes ago       Exited (0) 2 minutes ago                       thirsty_stallman
48a415dde98a        centos              "/bin/bash"         3 hours ago         Up 2 hours                                     nauseous_ardinghelli

启动,停止,重启容器

[root@localhost~]# docker start thirsty_stallman    /启动名字为thirsty_stallman的容器
[root@localhost~]# docker stop thirsty_stallman     /停止名字为thirsty_stallman的容器
[root@localhost~]# docker restart thirsty_stallman  /重启名字为thirsty_stallman的容器


重命名容器的名字

[root@localhost~]# docker rename nauseous_ardinghelli controller      /将容器名字为nauseous_ardinghelli更改成controller

进入与容器的交互模式

[root@localhost~]# docker attach nauseous_ardinghelli
[root@48a415dde98a ~]# 

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Docker — 云时代的程序分发方式 要说最近一年云计算业界有什么大事件?Google Compute Engi...
    ahohoho阅读 15,712评论 15 147
  • 概况 掌握 Docker 在Centos的安装: 操作系统:Win 10 家庭中文版 虚拟机软件:Oracle V...
    andy0898阅读 4,731评论 1 9
  • 一、Docker 简介 Docker 两个主要部件:Docker: 开源的容器虚拟化平台Docker Hub: 用...
    R_X阅读 9,847评论 0 27
  • 上一节 引子二、异响 夜幕缓缓降临了,黑暗并没有吞噬掉白天的哀伤。 保柱家,死气沉沉,十岁的秀英和狗蛋,偎依在墙角...
    四叶草_广广阅读 3,047评论 10 7
  • 说起信仰就会想起形形色色的宗教派系,熟悉的人中我姑姑是信佛教的,后来不知怎么我爸爸也开始信起来,初一十五都...
    管豹阅读 2,688评论 0 1

友情链接更多精彩内容