s
- docker yum源文件
查看代码
[root@localhost yum.repos.d]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@localhost yum.repos.d]# uname -r # 查看内核版本
3.10.0-1160.el7.x86_64
[root@localhost yum.repos.d]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
[root@localhost yum.repos.d]# cat /etc/yum.repos.d/docker-ce.repo
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://download.docker.com/linux/centos/$releasever/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-stable-debuginfo]
name=Docker CE Stable - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/$releasever/debug-$basearch/stable
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-stable-source]
name=Docker CE Stable - Sources
baseurl=https://download.docker.com/linux/centos/$releasever/source/stable
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-test]
name=Docker CE Test - $basearch
baseurl=https://download.docker.com/linux/centos/$releasever/$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-test-debuginfo]
name=Docker CE Test - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/$releasever/debug-$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-test-source]
name=Docker CE Test - Sources
baseurl=https://download.docker.com/linux/centos/$releasever/source/test
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-nightly]
name=Docker CE Nightly - $basearch
baseurl=https://download.docker.com/linux/centos/$releasever/$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-nightly-debuginfo]
name=Docker CE Nightly - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/$releasever/debug-$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-nightly-source]
name=Docker CE Nightly - Sources
baseurl=https://download.docker.com/linux/centos/$releasever/source/nightly
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
- 查看docker版本
[root@localhost yum.repos.d]# docker version
Client:
Version: 18.09.9
API version: 1.39
Go version: go1.11.13
Git commit: 039a7df9ba
Built: Wed Sep 4 16:51:21 2019
OS/Arch: linux/amd64
Experimental: false
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
问题3
[root@centos7 ~]# vim /etc/docker/daemon.json
{
"graph" : "/home/lab/docker/store" ,
"storage-driver" : "overlay2"
}
[root@centos7 ~]# docker info
Cannot connect to the Docker daemon at unix:///var/run/docker.sock.Is the docker daemon running?
[root@centos7 docker]# ls /etc/docker/certs.d key.json seccomp.json daemon.json
[root@centos7 docker]# systemctl restart docker.serviceJob for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
解决3
[root@centos7 docker]# systemctl status docker.service
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2020-08-19 10:51:57 CST; 1min 2s ago
Docs: http://docs.docker.com
Process: 3504 ExecStart=/usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current --init-path=/usr/libexec/docker/docker-init-current --seccomp-profile=/etc/docker/seccomp.json $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY $REGISTRIES (code=exited, status=1/FAILURE)
Main PID: 3504 (code=exited, status=1/FAILURE)
Aug 19 10:51:57 centos7 systemd[1]: Starting Docker Application Container Engine...
Aug 19 10:51:57 centos7 dockerd-current[3504]: unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives don't match any configuration option: archMap, s... defaultAction
Aug 19 10:51:57 centos7 systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
Aug 19 10:51:57 centos7 systemd[1]: Failed to start Docker Application Container Engine.
Aug 19 10:51:57 centos7 systemd[1]: Unit docker.service entered failed state.
Aug 19 10:51:57 centos7 systemd[1]: docker.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
[root@centos7 docker]# journalctl -xe
-- Unit docker.service has begun starting up.
Aug 19 09:53:04 centos7 dockerd-current[29211]: unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives are specified both as a flag and in the configuration file: grap
Aug 19 09:53:04 centos7 systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
Aug 19 09:53:04 centos7 systemd[1]: Failed to start Docker Application Container Engine.
-- Subject: Unit docker.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit docker.service has failed.
原因:自定义/etc/docker/daemon.json 中 含有--graph=/xxxx 的自定义存储路径与 /etc/sysconfig/docker 中 参数--graph=/home/lab/docker/images
Docker(十六)-Docker的daemon.json的作用
[root@centos7 ~]# rm -f /etc/docker/daemon.json
[root@centos7 ~]# systemctl restart docker.service
[root@centos7 store]# docker -vDocker version 1.13.1, build 64e9980/1.13.1
Docker修改默认存储位置(转)
https://blog.51cto.com/forangela/1949947
方法一、软链接
默认情况下Docker的存放位置为:/var/lib/docker
可以通过下面命令查看具体位置:
sudo docker info | grep "Docker Root Dir"
解决这个问题,最直接的方法当然是挂载分区到这个目录,但是我的数据盘还有其他东西,这肯定不好管理,所以采用修改镜像和容器的存放路径的方式达到目的。
这个方法里将通过软连接来实现。
首先停掉Docker服务:
systemctl restart docker或者service docker stop
然后移动整个/var/lib/docker目录到目的路径:
mv /var/lib/docker /root/data/dockerln -s /root/data/docker /var/lib/docker
这时候启动Docker时发现存储目录依旧是/var/lib/docker,但是实际上是存储在数据盘的,你可以在数据盘上看到容量变化。
方法二、修改镜像和容器的存放路径
指定镜像和容器存放路径的参数是--graph=/var/lib/docker,我们只需要修改配置文件指定启动参数即可。
Docker 的配置文件可以设置大部分的后台进程参数,在各个操作系统中的存放位置不一致,在 Ubuntu 中的位置是:/etc/default/docker,在 CentOS 中的位置是:/etc/sysconfig/docker。
如果是 CentOS6 则添加下面这行:
OPTIONS=--graph="/root/data/docker" --selinux-enabled -H fd://
如果是 Ubuntu 则添加下面这行(因为 Ubuntu 默认没开启 selinux):
OPTIONS=--graph="/root/data/docker" -H fd://# 或者DOCKER_OPTS="-g /root/data/docker"
最后重新启动,Docker 的路径就改成 /root/data/docker 了。
centos7下,也可以
修改docker.service文件,使用-g参数指定存储位置
vi /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd --graph /new-path/docker
// reload配置文件
systemctl daemon-reload
// 重启docker
systemctl restart docker.service
如果docker是1.12或以上的版本,可以修改(或新建)daemon.json文件。修改后会立即生效,不需重启docker服务。
vim /etc/docker/daemon.json
{"registry-mirrors": ["http://7e61f7f9.m.daocloud.io"],"graph": "/new-path/docker"}
方法三、system下创建配置文件
在/etc/systemd/system/docker.service.d 目录下创建一个Drop-In文件“docker.conf”,默认 docker.service.d 文件夹不存在。所以你必须先创建它。
创建Drop-In 文件的原因,是我们希望Docker 服务,使用docker.conf文件中提到的特定参数,将默认服务所使用的位于/lib/systemd/system/docker.service文件中的参数进行覆盖。如果你想深入了解Drop-In,请阅读system.unit文档
定义新的存储位置现在打开docker.conf增加如下内容:
# sudo vi /etc/systemd/system/docker.service.d/docker.conf
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --graph="/mnt/new_volume" --storage-driver=devicemapper
保存并退出VI编辑器,/mnt/new_volume 是新的存储位置,而devicemapper是当前docker所使用的存储驱动。如果你的存储驱动有所不同,请输入之前第一步查看并记下的值。Docker官方文档中提供了更多有关各种存储驱动器的信息。现在,你可以重新加载服务守护程序,并启动Docker服务了。这将改变新的镜像和容器的存储位置。
# sudo systemctl daemon-reload
# sudo systemctl start docker
为了确认一切顺利,运行 # docker info 命令检查Docker 的根目录.它将被更改为/mnt/new_volume
方法四、使用docker-storage-set(docker1.12)命令进行配置
配置文件位置:/usr/lib/docker-storage-setup/docker-storage-setup或者/etc/sysconfig/docker-storage-setup、/etc/sysconfig/docker-storage
vim /etc/sysconfig/docker-storage
# This file may be automatically generated by an installation program.
# Please DO NOT edit this file directly. Instead edit
# /etc/sysconfig/docker-storage-setup and/or refer to
# "man docker-storage-setup".
# By default, Docker uses a loopback-mounted sparse file in
# /var/lib/docker. The loopback makes it slower, and there are some
# restrictive defaults, such as 100GB max storage.
DOCKER_STORAGE_OPTIONS=--graph="要保存的路径"
或者
DEVS=/dev/vdb
DATA_SIZE=800GB(更改docker默认存储大小)
end