《Docker系列》Docker安装、运维教程
Error response from daemon: driver failed... Error: failed to start containers...
文章目录
Docker安装、运维教程
一、Docker安装
1 添加docker到yum源
1.1 安装
[root@hadoop ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
-bash: yum-config-manager: 未找到命令
1.2.尝试安装yum-config-manager
[root@hadoop apps]# yum install -y yum-config-manager
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* epel: mirrors.ustc.edu.cn
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
没有可用软件包 yum-config-manager。
错误:无须任何处理
1.3.经查询,系统没有这个yum-config-manager命令,在yum-utils包里。
[root@hadoop apps]# yum -y install yum-utils
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
已安装:
yum-utils.noarch 0:1.1.31-54.el7_8
完毕!
1.4.再次安装
[root@hadoop apps]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已加载插件:fastestmirror
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
2 安装docker
2.1. 安装docker
[root@hadoop yum.repos.d]# yum -y install docker-ce
2.2. 配置
[root@hadoop yum.repos.d]# mkdir -p /etc/docker
[root@hadoop yum.repos.d]# mkdir -p /data/apps/docker
2.3. 将daemon.json拷贝到/data/apps/docker
2.4. 启动docker
[root@hadoop yum.repos.d]# systemctl start docker
[root@hadoop docker]# ps -ef | grep docker
root 5791 1 0 09:04 ? 00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root 6014 1896 0 09:05 pts/0 00:00:00 grep --color=auto docker
[root@hadoop docker]#
docker ps 查看运行中容器(方便停止)
docker stop id
docker ps -a查看所有容易(方便重启和删除)
docker start id
docker rm id
3 安装可视化管理页面
3.1查找poratiner版本
[root@hadoop_zxy ~]# docker search portainer NAME DESCRIPTION STARS OFFICIAL AUTOMATED 6053537/portainer-ce portainer-ce中文汉化版 21 lihaixin/portainer docker ui 15 [OK] 6053537/portainer portainer中文版,完整汉化,汉化程度95%以上 6 greenled/portainer-stack-utils Bash scripts to deploy/undeploy stacks in a … 6 [OK] portainerci/portainer Portainer images automatically created via P… 5 cqkz/portainer-zh portainer-ce:2.1.1-alpine,汉化文件来自恩山… 3 hassioaddons/portainer 2 softonic/portainer-endpoint Allows auto register all the swarm nodes in … 1 [OK] thibaudlabat/portainer_32 Portainer built for 32bit Linux [ OUTDATED ]… 1 hassioaddons/portainer-armv7 1 xanderstrike/portainer-issue for illustrating a portainer issue 0 antsoftxyz/portainer-api A portainer api wrapper which can help you C… 0 portainerci/agent Portainer agent images automatically created… 0 portainerci/portainer-ee Portainer EE CI repository 0 helloysd/portainer 0 mitigram/portainer-ce Easily Configurable Portainer (CE Edition) 0 11384eb/portainer 0 nenadilic84/portainer 0 iconviet/portainer 0 hassioaddons/portainer-amd64 0 agiper/portainer 0 johnvmt/portainer-ecr-credentials Periodically updates the credentials Portain… 0 [OK] webdevsvc/portainer portainer 0 [OK] profidata/portainer Fork of portioner/portainer 0 geosite/portainer A Docker UI, This is a fork of portainer/por… 0 [
3.2 安装
[root@hadoop_zxy ~]# docker pull 6053537/portainer-ce Using default tag: latest latest: Pulling from 6053537/portainer-ce 0ea73420e2bb: Pull complete c367f59be2e1: Pull complete a6ce72cb0ef8: Pull complete Digest: sha256:27608553016612ae5373044376fa3274de3d3c9144e17a16211cb15e3faf2f5a Status: Downloaded newer image for 6053537/portainer-ce:latest docker.io/6053537/portainer-ce:latest
3.3运行
[root@hadoop_zxy ~]# docker run -d -p 1000:1000 \ > --restart=always \ > -v /var/run/docker.sock:/var/run/docker.sock \ > --name prtainer-test \ > docker.io/portainer/portainer Unable to find image 'portainer/portainer:latest' locally latest: Pulling from portainer/portainer 94cfa856b2b1: Pull complete 49d59ee0881a: Pull complete a2300fd28637: Pull complete Digest: sha256:fb45b43738646048a0a0cc74fcee2865b69efde857e710126084ee5de9be0f3f Status: Downloaded newer image for portainer/portainer:latest 5954df65ea1dbe8ef45d1fe742e7bc7a4b7fdad1da1a8cbc01e4049963277a6d
3.4查看
ip+port网页查看
二、Error response from daemon: driver failed… Error: failed to start containers…
1 docker启动异常
[root@zxy_slave1 ~]# docker start 26778a7f73a3
Error response from daemon: driver failed programming
external connectivity on endpoint oracle11g (6992d55d24b8fc6236595a0f3be92a3ee50c12646ed9394ede227560e0dbf393): (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 1521 -j DNAT --to-destination 172.17.0.3:1521 ! -i docker0: iptables: No chain/target/match by that name.
(exit status 1))
Error: failed to start containers
: 26778a7f73a3
2 重启docker
[root@zxy_slave1 ~]# systemctl restart docker
3 查看当前docker容器
[root@zxy_slave1 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
26778a7f73a3 registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g “/bin/sh -c '/home/o…” 9 months ago Exited (137) 3 hours ago oracle11g
07e54091826d portainer/portainer “/portainer” 9 months ago Up 5 seconds 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp prtainer-test
4 再次启动docker容器
[root@zxy_slave1 ~]# docker start 26778a7f73a3
26778a7f73a3
5 启动成功
[root@zxy_slave1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
26778a7f73a3 registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g “/bin/sh -c '/home/o…” 9 months ago Up 3 seconds 0.0.0.0:1521->1521/tcp, :::1521->1521/tcp oracle11g
07e54091826d portainer/portainer
三、Docker容器修改配置文件后,重启失败,如何修改配置并启动容器?
docker部署的MySQL容器,修改了my.cnf
配置文件,重启的时候导致无法启动
通过查日志发现,配置文件中的binlog-db-db=hw
写错了,应该是binlog-do-db=hw
。
这时候需要修改配置文件,才能启动,但是呢?容器又启动不了
这种情况可以通过两种方式处理
[root@zxy_master mysql03]# docker logs e1aa5d676710
2023-03-03 08:27:23+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.40-1.el7 started.
2023-03-03 08:27:23+00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config
command was: mysqld --verbose --help --log-bin-index=/tmp/tmp.uebX7jnPYr
2023-03-03T08:27:23.657000Z 0 [ERROR] unknown variable 'binlog-db-db=hw'
2023-03-03T08:27:23.660333Z 0 [ERROR] Aborting
2023-03-03 08:27:52+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.40-1.el7 started.
2023-03-03 08:27:52+00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config
command was: mysqld --verbose --help --log-bin-index=/tmp/tmp.HmpBPq7emF
2023-03-03T08:27:52.311118Z 0 [ERROR] unknown variable 'binlog-db-db=hw'
2023-03-03T08:27:52.314845Z 0 [ERROR] Aborting
方式一:查找跟docker容器映射的本地文件
docker inspect [容器ID]
查看容器详情时,主要关注Mounts
处,可以查看到跟容器映射的本地文件,修改后即可成功启动。
我采用的是第二种方法,所以对方式一不做太多说明,可以自行尝试。
"Mounts": [
{
"Type": "bind",
"Source": "/zxy/apps/docker_mysql/mysql03/log",
"Destination": "/var/log/mysql",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
},
{
"Type": "bind",
"Source": "/zxy/apps/docker_mysql/mysql03/data",
"Destination": "/var/lib/mysql",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
},
{
"Type": "bind",
"Source": "/zxy/apps/docker_mysql/mysql03/conf",
"Destination": "/etc/mysql/conf.d",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
方式二:拷贝容器文件到本地,修改后再上传
# 1.复制容器文件到本地
[root@zxy_master data]# docker cp e1aa5d676710:/etc/my.cnf ./
# 2.修改错误项
[root@zxy_master data]# vim my.cnf
# 3.复制修改后文件到容器
[root@zxy_master data]# docker cp ./my.cnf e1aa5d676710:/etc/my.cnf
# 4.重启成功
[root@zxy_master data]# docker start e1aa5d676710
e1aa5d676710
更多推荐
所有评论(0)