阿里云docker环境搭建和问题解决
背景在新买的阿里云在线搭建docker环境当前系统环境lsb_release -a# 查看系统详细信息命令[root@iZbp18sxd8cxak3k30znshZ docker]# lsb_release -aLSB Version::core-4.1-amd64:core-4.1-noarchDistributor ID:AlibabaCloud(AliyunLinux)Description
背景
在新买的阿里云在线搭建docker环境
当前系统环境
lsb_release -a
# 查看系统详细信息命令
[root@iZbp18sxd8cxak3k30znshZ docker]# lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: AlibabaCloud(AliyunLinux)
Description: Alibaba Cloud Linux (Aliyun Linux) release 2.1903 LTS (Hunting Beagle)
Release: 2.1903
Codename: HuntingBeagle
uname -a
[root@iZbp18sxd8cxak3k30znshZ docker]# uname -a
Linux iZbp18sxd8cxak3k30znshZ 4.19.91-24.1.al7.x86_64 #1 SMP Wed Jul 21 17:40:23 CST 2021 x86_64 x86_64 x86_64 GNU/Linux
安装docker
yum install docker
# 执行安装命令,中间会有个安装确认提示框选择yes就行了
[root@iZbp18sxd8cxak3k30znshZ docker]# vi /etc/docker/daemon.json.rpmsave
[root@iZbp18sxd8cxak3k30znshZ docker]# yum install
Loaded plugins: fastestmirror, langpacks, update-motd
Error: Need to pass a list of pkgs to install
Mini usage:
install PACKAGE...
Install a package or packages on your system
aliases: install-n, install-na, install-nevra
[root@iZbp18sxd8cxak3k30znshZ docker]# yum install docker
Loaded plugins: fastestmirror, langpacks, update-motd
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 2:1.13.1-108.git4ef4b30.1.al7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================================================================================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================================================================================================================================================
Installing:
docker x86_64 2:1.13.1-108.git4ef4b30.1.al7 extras 22 M
Transaction Summary
==============================================================================================================================================================================================================================================================================
Install 1 Package
Total download size: 22 M
Installed size: 77 M
Is this ok [y/d/N]: y
Downloading packages:
docker-1.13.1-108.git4ef4b30.1.al7.x86_64.rpm | 22 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 2:docker-1.13.1-108.git4ef4b30.1.al7.x86_64 1/1
Verifying : 2:docker-1.13.1-108.git4ef4b30.1.al7.x86_64 1/1
Installed:
docker.x86_64 2:1.13.1-108.git4ef4b30.1.al7
Complete!
查看docker版本
docker version
有个提示cannot connect to the Docker.... 表示当前docker服务没有启动
[root@iZbp18sxd8cxak3k30znshZ docker]# docker version
Client:
Version: 1.13.1
API version: 1.26
Package version:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
启动docker服务
systemctl start docker
PS:如果不报错基本上就启动成功
再次查看docker版本
[root@iZbp18sxd8cxak3k30znshZ docker]# docker version
Client:
Version: 1.13.1
API version: 1.26
Package version: docker-1.13.1-108.git4ef4b30.1.al7.x86_64
Go version: go1.13.3
Git commit: 4ef4b30/1.13.1
Built: Fri Jan 31 15:01:11 2020
OS/Arch: linux/amd64
Server:
Version: 1.13.1
API version: 1.26 (minimum version 1.12)
Package version: docker-1.13.1-108.git4ef4b30.1.al7.x86_64
Go version: go1.13.3
Git commit: 4ef4b30/1.13.1
Built: Fri Jan 31 15:01:11 2020
OS/Arch: linux/amd64
Experimental: false
配置docker日志
默认的路径为:/etc/docker/daemon.json(其中是空的)
vi /etc/docker/daemon.json
log-driver: 配置生成文件的类型
log-opts:配置文件的最大值和最大文件数量
{
"log-driver":"json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}
重新启动
systemctl restart docker
# 重启之后有可能会出现问题 (有可能是因为历史安装中指定了默认日志生成方式比如 log-driver=journald )
[root@iZbp18sxd8cxak3k30znshZ docker]# systemctl restart docker
Job for docker.service failed because the control process exited with error code.
See "systemctl status docker.service" and "journalctl -xe" for details.
详细错误日志
systemctl status docker.service
[root@iZbp18sxd8cxak3k30znshZ docker]# systemctl status docker.service
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2021-07-28 13:20:10 CST; 2s ago
Docs: http://docs.docker.com
Process: 4754 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: 4754 (code=exited, status=1/FAILURE)
Jul 28 13:20:10 iZbp18sxd8cxak3k30znshZ systemd[1]: Starting Docker Application Container Engine...
Jul 28 13:20:10 iZbp18sxd8cxak3k30znshZ dockerd-current[4754]: 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: log-driver: (from flag: jour... from file: local)
Jul 28 13:20:10 iZbp18sxd8cxak3k30znshZ systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
Jul 28 13:20:10 iZbp18sxd8cxak3k30znshZ systemd[1]: Failed to start Docker Application Container Engine.
Jul 28 13:20:10 iZbp18sxd8cxak3k30znshZ systemd[1]: Unit docker.service entered failed state.
Jul 28 13:20:10 iZbp18sxd8cxak3k30znshZ systemd[1]: docker.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
产生原因
启动命令中的日志模式和守护进程中的模式产生了冲突
启动命令配置路径为:/etc/sysconfig/docker
解决
在启动中的参数删除掉,在日志守护进程中配置日志生成的类型
重新启动
systemctl restart docker
配置开机启动
systemctl enable docker.service
查看所有的容器信息
docker ps -a
至此 完成安装
[root@iZbp18sxd8cxak3k30znshZ sysconfig]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
离线安装
如果想在内网离线安装可以修改yum的配置项将下载的文件都拷贝到目标机器安装
配置路径: /etc/yum.conf
配置项为: keepcache=1 (保存下载下来的安装包)
主要配置项
默认是: /var/cache/yum/****
也可以在 /etc/yum.conf 指定
cachedir=/var/cache/yum #存放目录
keepcache=1 #1为保存 0为不保存
metadata_expire=1800 #过期时间
更多推荐
所有评论(0)