centos7 docker安装,centos如何安装软件
大家好,如果您还对centos7 docker安装不太了解,没有关系,今天就由本站为大家分享centos7 docker安装的知识,包括centos如何安装软件的问题都会给大家分析到,还望可以解决大家的问题,下面我们就开始吧!
如何在 CentOS 7 上安装 Docker
CentOS 7中 Docker的安装
Docker软件包已经包括在默认的 CentOS-Extras软件源里。因此想要安装 docker,只需要运行下面的 yum命令:
[root@localhost~]# yum install docker
启动 Docker服务
安装完成后,使用下面的命令来启动 docker服务,并将其设置为开机启动:
[root@localhost~]# service docker start[root@localhost~]# chkconfig docker on
(LCTT译注:此处采用了旧式的 sysv语法,如采用CentOS 7中支持的新式 systemd语法,如下:
[root@localhost~]# systemctl start docker.service[root@localhost~]# systemctl enable docker.service
)
下载官方的 CentOS镜像到本地
[root@localhost~]# docker pull centosPulling repository centos192178b11d36: Download complete 70441cac1ed5: Download complete ae0c2d0bdc10: Download complete 511136ea3c5a: Download complete 5b12ef8fd570: Download complete
确认 CentOS镜像已经被获取:
[root@localhost~]# docker images centosREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEcentos centos5 192178b11d36 2 weeks ago 466.9 MBcentos centos6 70441cac1ed5 2 weeks ago 215.8 MBcentos centos7 ae0c2d0bdc10 2 weeks ago 224 MBcentos latest ae0c2d0bdc10 2 weeks ago 224 MB
运行一个 Docker容器:
[root@localhost~]# docker run-i-t centos/bin/bash[root@dbf66395436d/]#
我们可以看到,CentOS容器已经被启动,并且我们得到了 bash提示符。在 docker命令中我们使用了“-i捕获标准输入输出”和“-t分配一个终端或控制台”选项。若要断开与容器的连接,输入 exit。
[root@cd05639b3f5c/]# cat/etc/redhat-release CentOS Linux release 7.0.1406(Core) [root@cd05639b3f5c/]# exitexit[root@localhost~]#
我们还可以搜索基于 Fedora和 Ubuntu操作系统的容器。
[root@localhost~]# docker search ubuntu[root@localhost~]# docker search fedora
显示当前正在运行容器的列表
centos7 docker 初次安装遇见问题&运用
初次安装CentOS Docker所遇问题与解决方法及基本用法详解
在初次尝试安装CentOS Docker时,可能会遇到报错“Error response from daemon: Get index.docker.io/v1/sear... x509: certificate has expired or s not yet valid”。此问题的解决方法是,首先需要更改Docker的注册镜像源至国内镜像站点,操作步骤如下:
1.打开配置文件/etc/docker/daemon.json,添加如下内容:
{
"registry-mirrors":[""]
}
2.保存并退出编辑,重启Docker服务
3.重新尝试运行docker search centos,错误应已解决。
接下来,开启网络转发功能以避免后续操作中的问题:
1.执行命令vim/etc/sysctl.conf,在文件中添加以下内容:
net.ipv4.ip_forward= 1
2.执行命令sysctl-p使配置生效。
3.使用cat/proc/sys/net/ipv4/ip_forward验证网络转发功能已开启。
完成以上步骤后,CentOS Docker已准备好使用,下面列举了Docker的基本用法:
1.拉取镜像:docker pull docker.io/centos
2.加载本地镜像:docker load-i/root/docker.io-centos.tar
3.拉取指定仓库的镜像:docker pull hub.c.163.com/library/t...
4.运行容器(交互模式):docker run-it docker.io/centos:latest/bin/bash
5.运行容器(后台模式):docker run-d docker.io/centos:latest/bin/sh-c"while true;do echo hello world; sleep 1; done"
6.列出所有镜像:docker images
7.列出运行中的容器:docker ps
8.显示所有容器(包括已停止的):docker ps-a
9.启动容器:docker start容器ID/容器NAMES
10.停止容器:docker stop容器ID/容器NAMES
11.查看容器日志:docker logs容器ID
12.杀死容器:docker kill容器ID
13.重启容器:docker restart容器ID
14.删除容器:docker rm-f容器ID
通过以上操作,可实现容器的创建、运行、管理与镜像的创建、加载、拉取与发布。
在创建镜像的过程中,可以使用两种方法:
方法一:通过容器执行命令,生成新镜像。
方法二:编写Dockerfile文件,通过Dockerfile构建镜像。
在使用过程中,需注意删除镜像前必须先停止并删除相关的容器实例。
此外,Docker容器的命名与重命名、主机名操作也较为简单,使用`docker run`命令时可指定容器名,如`docker run-itd--name docker1 docker.io/centos:latest/bin/bash`。容器数据映射则是通过 `-p`参数指定端口映射。
centos7怎么安装docker
安装docker
1、Docker要求 CentOS系统的内核版本高于 3.10,查看本页面的前提条件来验证你的CentOS版本是否支持 Docker。
通过 uname-r命令查看你当前的内核版本
$ uname-r
2、使用 root权限登录 Centos。确保 yum包更新到最新。
$ sudo yum update
3、卸载旧版本(如果安装过旧版本的话)
$ sudo yum remove docker docker-common docker-selinux docker-engine
4、安装需要的软件包, yum-util提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
$ sudo yum install-y yum-utils device-mapper-persistent-data lvm2
5、设置yum源
$ sudo yum-config-manager--add-repo
6、可以查看所有仓库中所有docker版本,并选择特定版本安装
$ yum list docker-ce--showduplicates| sort-r
7、安装docker
$ sudo yum install docker-ce#由于repo中默认只开启stable仓库,故这里安装的是最新稳定版17.12.0
$ sudo yum install<FQPN>#例如:sudo yum install docker-ce-17.12.0.ce
8、启动并加入开机启动《Linux就该这么学》
$ sudo systemctl start docker
$ sudo systemctl enable docker
9、验证安装是否成功(有client和service两部分表示docker安装启动都成功了)
$ docker version