美文网首页
虚机中安装docker

虚机中安装docker

作者: kikey | 来源:发表于2016-11-24 13:15 被阅读0次

登陆

1.通过xshell用root用户登陆虚机机

安装

2.执行yum install docker 安装docker

yum -y install docker 就可以不用中间的确认交互了

启动docker服务

[root@localhost /]# service docker start

Redirecting to /bin/systemctl start  docker.service

将docker加入开机启动

[root@localhost /]# chkconfig docker on

Note: Forwarding request to 'systemctl enable docker.service'.

Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

测试安装成功docker images 查看是否有镜像

[root@localhost ~]# docker images

REPOSITORY          TAG                IMAGE ID            CREATED            SIZE

下载运行镜像

https://hub.docker.com/ 上查看需要的镜像

可以直接用docker run ,如果没有该镜像会主动去官网下载镜像。也可以提前用

docker pull下载,若在镜像后没有加版本信息,默认为latest

docker run -i -t -d docker.io/centos /bin/bash

c876b0f96b330642d51c929b215a7430ac44e14549661a1c91d9e54770b3195d

查看运行的容器 

查看刚才运行的容器

[root@localhost /]# docker ps

CONTAINER ID        IMAGE              COMMAND            CREATED            STATUS              PORTS              NAMES

c876b0f96b33        docker.io/centos    "/bin/bash"        3 minutes ago      Up 3 minutes                            gloomy_kirch

进入和退出容器

进入容器:命令 docker attach + CONTAINER ID

[root@localhost /]# docker attach c876b0f96b33

[root@c876b0f96b33 /]#

[root@c876b0f96b33 /]#exit

exit

[root@localhost /]#

如何退出容器而不停止容器?组合键:Ctrl+P+Q

给容器中的CentOS安装ifconfig

[root@c876b0f96b33 /]# ifconfig

bash: ifconfig: command not found

因为默认的CentOS中没有安装ifconfig,你无法知道该操作系统的IP,可以通过2中方式给镜像安装

ifconfig软件。

1.在运行的容器里安装软件,然后commint成新的镜像。

在容器里依次运行

yum search ifconfig

yum install -y net-tools.x86_64

测试ifconfig命令成功后,exit容器

执行docker commit + CONTAINER ID + NEW IMAGENAME

然后images

[root@localhost mycentos]# docker images

REPOSITORY          TAG                IMAGE ID            CREATED            SIZE

my/mycentos        latest              65f4293bb333        3 days ago          309.5 MB

2.通过dockerfile生产新的镜像。

编写一个Dockerfile文件

[root@localhost mycentos]# vi Dockerfile 

## MAINTAINER        hp.zheng

# DOCKER-VERSION    1.0.0

#

# Dockerizing CentOS: Dockerfile for building CentOS images

#

FROM      centos:latest

MAINTAINER hp.zheng

RUN yum search ifconfig

RUN yum install -y net-tools.x86_64

RUN yum clean all

相关文章

网友评论

      本文标题:虚机中安装docker

      本文链接:https://www.haomeiwen.com/subject/thmkpttx.html