Docker的本地安装
下载docker的离线安装包
解压docker
tar -zxvf docker.tgz
拷贝docker目录到/usr/bin/目录下
cp /usr/local/docker/* /usr/bin/
编辑/etc/systemd/system/docker.sevice
填入下面内容
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
启动docker
chmod +x /etc/systemd/system/docker.service 添加权限
systemctl daemon-reload 重新加载守护进程
systemctl start docker 启动docker
systemctl enable docker.service 添加docker的开机自启
systemctl status docker 查看docker状态
Docker仓库
由于Docker-Hub的链接不稳定与公司的内网环境限制,所以需要自己搭建Docker的私服,借助的工具是Nexus。对!没错,就是用来搭建maven私服的那个东西,这东西真好用,yum源都可以在这里面搭,哇哈哈哈,不用到处去找了!
这里都有:链接:https://pan.baidu.com/s/1o3VV2kGF3BiNs2UEwXGhSQ
提取码:r80g
Nexus安装
这里不写了,贼简单,就是解压完事儿启动。如果有需要后续补充链接
Nexus配置docker仓库
是的没错,就按照上面的顺序点,点完就可以配置docker的仓库了。
是的没错,就按照上面的修改,端口修改成未被占用的就可以
就到这里了,你的仓库建好了~~~
docker关联仓库
在/etc/docker/下新建daemon.json
填入下面的内容
{
"registry-mirrors": ["https://registry.docker-cn.com"],
"insecure-registries":["机器的IP:6000"]
}
重启你的docker
systemctl restart docker.service
是的你现在已经可以访问你的仓库了
使用docker登陆
docker login IP:6000
输入你的Nexus的账号和密码
是的你登陆成功了
创建一个docker镜像
访问这个地址,你可以获得一个Centos的镜像:https://github.com/CentOS/sig-cloud-instance-images/tree/2cd93d6632e5476306240ce66a7a1ff929a6997f
运行里面的dockerfile
docker build -t 5588/centos-ssh:v1.0.0 .
你的docker镜像生成好了来一起看看吧
docker images
你已经看到了你的镜像
试着启动它一下吧
docker run -itd -p 10022:22 --name test_centos_1 5588/centos-ssh:v1.0.0 #启动容器
使用dokcer ps 你应该已经可以看到你的docker镜像启动起来了
来我们登陆一下
ssh -p10022 127.0.0.1
输入dockerfile中的密码,没错你已经进来了
docker提交镜像
把正在运行的container进行打包,打包成image
#打包成image
docker commit -m "My First Image" -a "Abey" 4297d2a55e29 centos_2
# -m 给镜像个描述
#-a 给镜像个作者
#4297d2a55e29 镜像的ID
#centos_2 生成的镜像名
#给生成的image打个标签
docker tag 9a373871ab91 10.192.33.253:6000/centos_2
#9a373871ab91 镜像的id docker ps 可以获取
#10.192.33.253:6000/centos_2 仓库地址和保存路径
docker推送镜像到docker镜像私服Nexus中
docker push 10.192.33.253:6000/centos_2
嗯是的,我推到远程库了
那我们怎么拉取呢,
docker pull 10.192.33.253:6000/centos_2
我就拉取下来了呢
DevOps第一步已经迈出,敬请期待后续~~~