栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

docker的使用

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

docker的使用

docker

安装


文章目录

docker一、docker的安装(aliyun)二、docker镜像三、Dockerfile方式


前言
先配虚拟机,保证可以联网。
本文采用rehl7.6系统

一、docker的安装(aliyun)

[root@docker1 ~]# cd /etc/yum.repos.d/
[root@docker1 yum.repos.d]# ls
redhat.repo  rhel7.6.repo
[root@docker1 yum.repos.d]# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

修改下仓库配置文件,删掉先不用的,方便当前阶段测试使用。

[root@docker1 yum.repos.d]# cat docker-ce.repo
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/stable
enabled=1
gpgcheck=0
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg


安装docer

[root@docker1 yum.repos.d]# yum install docker-ce

若发现依赖性的问题有如下解决方案
还是再阿里云上
找一个centos7的仓库
wget https://mirrors.aliyun.com/repo/Centos-7.repo
调整下仓库,关掉不用的

[root@docker1 yum.repos.d]# cat Centos-7.repo
# CentOS-base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#
 
[base]
name=CentOS-$releasever - base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
enabled=0

#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
enabled=0
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/extras/$basearch/
gpgcheck=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
enabled=0

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
enabled=0

然后开启docker

[root@docker1 yum.repos.d]# systemctl start docker
[root@docker1 yum.repos.d]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@docker1 yum.repos.d]# docker info

info开启不成功
是因为火墙的问题

解决方法


在sysctl.d下新建一个文件

[root@docker1 yum.repos.d]# cat /etc/sysctl.d/docker.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1

然后启用
sysctl --system
再次输入docker info就好了

测试


运行后打开 浏览器
输入虚拟机ip+80端口

就可以看到运行的内容了

二、docker镜像

分层结构
共享资源
所有镜像层可读
最上层可写
操作对下层都不产生影响
过程就类似于累积木

以busybox为例展示

[root@docker1 ~]# docker pull busybox
Using default tag: latest
latest: Pulling from library/busybox
009932687766: Pull complete 
Digest: sha256:afcc7f1ac1b49db317a7196c902e61c6c3c4607d63599ee1a82d702d249a0ccb
Status: Downloaded newer image for busybox:latest
docker.io/library/busybox:latest

删掉原来的运行容器,再创建

[root@docker1 ~]# docker rm -f demo
demo
[root@docker1 ~]# docker  run -it --name demo busybox


此时就在可写容器层
退出后可以用
docker ps -a
来查看
在使用中可以用
ctrl+p+q
打入后台
docker stop demo(自定义名称)
完全退出
docker rm demo(自定义名称)
删除
若要保存操作可以用commit

此时可以保存所有操作
用history查看
这样就算删掉了demo
从v1开始创建,操作会保留

删除镜像
docker rmi demo1:v1
可以看到如果容器正在被占用,不能直接删除,必须先删掉demo1,然后才能删掉v1。v3没有被使用可以直接删除。

在history中信息也不符合企业生产环境中的安全规范性
效率也很低下
不建议使用这种方式
所以下面介绍另一种方式

三、Dockerfile方式

创建一个目录
然后在目录中创建文档Dockerfile

这样操作的步骤在history中都很清楚
操作步骤都可以重复利用,提升效率

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/741601.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号