安装docker容器各种填坑记录
最近服务器不够用了,重新拿了一个新机器进行测试环境维护。服务器安装过程中发现了有些问题如果提前处理后期就不必出现难以应付的局面,这里记录一下,免得再犯同样的问题。
问题一:docker安装jenkins拉取的镜像
[root@localhost tools]# docker search jenkins
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
jenkins DEPRECATED; use "jenkins/jenkins:lts" instead 5478 [OK]
jenkins/jenkins The leading open source automation server 3048
jenkins/jnlp-slave a Jenkins agent which can connect to Jenkins… 150 [OK]
jenkins/inbound-agent 65
bitnami/jenkins Bitnami Docker Image for Jenkins 51 [OK]
jenkins/slave base image for a Jenkins Agent, which includ… 48 [OK]
jenkins/agent 38
jenkins/ssh-slave A Jenkins slave using SSH to establish conne… 37 [OK]
jenkins/ssh-agent Docker image for Jenkins agents connected ov… 23
jenkins/jnlp-agent-docker 8
jenkins/jnlp-agent-maven A JNLP-based agent with Maven 3 built in 7
jenkins/pct Plugin Compat Tester 5 [OK]
jenkins/evergreen An automatically self-updating Jenkins distr… 5
jenkins/jnlp-agent-python A JNLP-based agent with Python built in 3
jenkins/jenkins-experimental Experimental images of Jenkins. These images… 3 [OK]
jenkins/jnlp-agent-alpine 2
jenkins/jnlp-agent-node 1
rancher/jenkins-jenkins 1
jenkins/ath Jenkins Acceptance Test Harness 1 [OK]
jenkins/jnlp-agent-ruby 1
jenkins/core-pr-tester Docker image for testing pull-requests sent … 1
jenkins/core-changelog-generator Tool for generating Jenkins core changelogs 1
jenkins/jenkinsfile-runner Jenkinsfile Runner packages 0
rancher/jenkins-slave Jenkins Build Slave 0 [OK]
rancher/jenkins-jnlp-slave 0
经查,jenkins有很多镜像,如图
jenkins/jenkins是官方维护的镜像,所以这里使用的镜像就是jenkins/jenkins;
# 获取最新镜像
# docker pull jenkins/jenkins:lts
这里获取如果不是最新的镜像,启动的时候可以出现各种插件安装失败的情况,所以为了避免此问题,建议一般都安装最新的版本
问题二:jenkins容器启动
jenkins容器启动时,需要挂载jenkis的工作目录和maven的路径到宿主机,这里一定要提前设置好
# 142 使用此安装
docker run \
--name jenkins \
-u root \
-d \
-p 9009:8080 \
-p 50001:50001 \
-v /usr/local/src/jdk1.8.0_152/bin/java:/usr/jdk8/jdk1.8.0_152/java \
-v /usr/local/src/jdk1.8.0_152:/usr/jdk8/jdk1.8.0_152 \
-v /tools/maven3:/tools/maven3 \
-v /data/jenkins_home:/var/jenkins_home \
-v /etc/localtime:/etc/localtime \
jenkins/jenkins
说明:
-v /data/jenkins_home:/var/jenkins_home 中的/var/jenkins_home是容器中jenkins的工作路径,一般情况此路径不变
问题三:容器网络不通
重新安装了docker之后,发现启动容器ping不通网以及公司内部的机器。网上资料很多,具体原因没找到,暂时解决方案选择重新装一下docker的网卡之后顺利解决。
现象:
通过 docker run --net host 创建的容器不存在上述的问题
解决方法:
#停止docker
systemctl stop docker
#docker0
ip link set dev docker0 down
#删除docker0网桥
brctl delbr docker0
#新增一个docker0网桥
brctl addbr docker0
#增加网卡(这里ip也完全使用这个)
ip addr add 172.16.0.0/24 dev docker0
#启用网卡
ip link set dev docker0 up
#重启docker服务
systemctl restart docker
问题四:容器默认存储路径更改
[root@localhost tools]# docker info
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
scan: Docker Scan (Docker Inc.)
Server:
Containers: 14
Running: 12
Paused: 0
Stopped: 2
Images: 40
Server Version: 20.10.6
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 05f951a3781f4f2c1911b05e61c160e9c30eaa8e
runc version: 12644e614e25b05da6fd08a38ffa0cfe1903fdec
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-1160.25.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 15.42GiB
Name: localhost.localdomain
ID: AOHK:O4AD:U4X4:OMNK:F6VD:GZVL:D5ZE:BZDU:433H:7NZQ:WM3A:TTAO
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: overlay2: the backing xfs filesystem is formatted without d_type support, which leads to incorrect behavior.
Reformat the filesystem with ftype=1 to enable d_type support.
Running without d_type support will not be supported in future releases.
[root@localhost tools]#
在安装docker时,默认的安装路径是Docker Root Dir: /var/lib/docker
更改步骤如下:
# 创建目录
mkdir /data
cd /data
mkdir docker
-----------
# 修改 docker 的 systemd 的 docker.service 的配置文件
# vim /usr/lib/systemd/system/docker.service
# ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (注释原先的)
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --graph=/data/docker(新增的)
---------
# 重新 enable 一下 docker 服务重新进行软连接以及进行一次 daemon-reload
systemctl daemon-reload
systemctl restart docker
这里我修改的是vi /etc/docker/daemon.json
{
"graph":"/data/docker",
"registry-mirrors": [ "https://docker.mirrors.ustc.edu.cn",
"https://reg-mirror.qiniu.com",
"https://hub-mirror.c.163.com"]
}
修改后发现之前的镜像和容器都不存在了,😆
建议容器安装好之后就更改容器的存储路径,避免出现不可预知的错误。