当前位置: 首页 » 综合知识 » it知识 » 正文

在CentOS7上安装Docker环境要注意哪些事项

发布时间:2023-07-22 以下文章来源于网友投稿,内容仅供参考!

以下操作均在root用户下完成

docker的安装要求64位系统且内核版本大于3.10。所以如果是centos的话,必须安装centos7.0或以上版本。
我们这里使用的是centos7.2 mininul。

uname -r
3.10.0-327.28.3.el7.x86_64

安装docker前执行一下全系统的软件版本升级:
yum -y update

1.配置yum软件库

为保证安装的成功,首先使用yum update更新yum包,表示我的好多yum包都需要更新,1500+的包,如果你像我一样好久没有更新过,那就耐心等候吧。
然后在yum软件库中新增docker的配置:

# tee /etc/yum.repos.d/docker.repo <<-'eof'
[dockerrepo]
name=docker repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
eof

2.安装docker

有了yum软件库的配置之后,安装也变得异常的简单,只需要以下一句即可:

# yum install docker-engine

3.启动docker
一切就绪之后,使用start命令来启动docker守护进程:

# service docker start

4.输出hello-world
程序员貌似跟hello-world有仇,有事儿没事就打印人家一下,玩docker咱们当前也不例外,先来个hello-world吧,这里的基本原理是利用人家已经写好的hello-world镜像,下载到本地,然后把他运行起来~

使用以下命令:

# docker run hello-world

然后控制端会输出类似于如下的信息,就证明我们的docker环境安装成功了~

在这里,我第一次失败了~显示:

unable to find image 'hello-world:latest' locally
docker: error response from daemon: get https://registry-1.docker.io/v2/library/hello-world/manifests/latest: get https://auth.docker.io/token?scope=repository%3alibrary%2fhello-world%3apull&service=registry.docker.io: net/http: tls handshake timeout.
see 'docker run --help'.

然后我又来了一次就好了,应该是墙的原因吧,看着是网络访问失败了~

unable to find image 'hello-world:latest' locally
latest: pulling from library/hello-world
c04b14da8d14: pull plete 
digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
status: downloaded newer image for hello-world:latest

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.
 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 hub account:
 https://hub.docker

for more examples and ideas, visit:
 https://docs.docker/engine/userguide/

设置为自启动:

chkconfig docker on

调整docker数据目录:

把一个独立的数据分区设置为docker数据目录,需手工把docker原目录的数据都移到新的存储分区上去,然后以新的存储分区挂载到/var/lib/docker目录下。

service docker stop

拷数据及挂分区:

service docker start

4、创建一个专用的docker group

docker是需要使用root权限运行的,但仍然可以通过创建一个专用的用户组的方式,让一个具备sudo权限的普通用户管理docker服务。

复制代码 代码如下:

# groupadd docker
# usermod -ag docker bjxtb

退出当前会话,重新登录后使用bjxtb直接管理docker:

$ docker run hello-world

运行一个 docker 容器:

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

我们可以看到,centos 容器已经被启动,并且我们得到了 bash 提示符。在 docker 命令中我们使用了 “-i 捕获标准输入输出”和 “-t 分配一个终端或控制台”选项。若要断开与容器的连接,输入 exit。

[root@cd05639b3f5c /]# cat /etc/redhat-release
centoslinux release 7.0.1406(core)
[root@cd05639b3f5c /]#exit
exit
[root@localhost ~]#

我们还可以搜索基于 fedora 和 ubuntu 操作系统的容器。

[root@localhost ~]# docker search ubuntu
[root@localhost ~]# docker search fedora

显示当前正在运行容器的列表

  • • Linux Ecdsa密钥长度选择有何依据

    在Linux

  • • Linux Khook在内核监控中的应用如何

    Linux

  • • Linux Gsoap是否支持异步通信

    GSOAP是

  • • Linux Coremail如何提升用户体验

    提升Linu

  • • Linux Ecdsa算法有哪些局限性

    ECDSA

  • 哎呀音乐钢琴键盘学习《 钢琴主人训练营》 西瓜学琴
    郭蝈 陪练钢琴 30节课时 考级刚需 让孩子每一次练琴都是高质量的
    30天轻松学会五线谱 流行钢琴自学初级教程 牙牙学琴
    流行爵士钢琴实战技巧VIP课 - 继伟 哎呀音乐
    【海上钢琴师】原版 MT1990钢琴谱
    百首经典流行钢琴实战曲集 - 继伟
    雷费尔德电钢琴重锤88键专业考级儿童初学者数码电子钢琴家用
    小练咖 真人钢琴陪练 1v1服务 2999随时退 1课时50分钟 考级刚需
    雅马哈电钢琴88键重锤CLP735智能数码电子钢琴家用专业初学者考级
    【原装进口】Yamaha/雅马哈钢琴 b121 SC2原声静音钢琴
  • 珠海专业调钢琴
  • 天津宝坻区调钢琴
  • 天津静海区钢琴调音
  • 成都简阳市钢琴调律
  • 大连瓦房店市钢琴调音
  • 眉山调钢琴联系方式
  • 惠州大亚湾钢琴调琴师
  • 长治调琴师
  • 厦门湖里区钢琴调音师
  • 上海普陀区钢琴调音师