docker容器入门之docker安装

话不多说,直接开始
1.docker安装
搭建本地 docker 源
首先确定自己系统是64位,且内核是3.1以上
虚拟机能连网的情况下
若本地虚拟机可以上网
执行命令
yum update

添加docker的yum源

tee /etc/yum.repos.d/docker.repo <<-‘EOF’
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF

安装docker服务
yum install docker-engine

安装完成后设置docker服务开机自启
systemctl enable docker.service
启动docker服务守护进程
systemctl start docker

到此docker服务安装完成,使用命令
docker info 查看
以我本地虚拟机为例
[root@localhost ~]# docker info
Containers: 17
Running: 12
Paused: 0
Stopped: 5
Images: 15
Server Version: 18.03.1-ce
Storage Driver: devicemapper
Pool Name: docker-253:0-33684101-pool
Pool Blocksize: 65.54kB
Base Device Size: 10.74GB
Backing Filesystem: xfs
Udev Sync Supported: true
Data file: /dev/loop0
Metadata file: /dev/loop1
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Data Space Used: 4.434GB
Data Space Total: 107.4GB
Data Space Available: 7.508GB
Metadata Space Used: 9.077MB
Metadata Space Total: 2.147GB
Metadata Space Available: 2.138GB
Thin Pool Minimum Free Space: 10.74GB
Deferred Removal Enabled: true
Deferred Deletion Enabled: true
Deferred Deleted Device Count: 0
Library Version: 1.02.146-RHEL7 (2018-01-22)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 773c489c9c1b21a6d78b5c538cd395416ec50f88
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-862.6.3.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.787GiB
Name: localhost.localdomain
ID: FWQ6:XQCQ:4BGX:HTSY:JSK2:FKPS:ETI7:QV7B:KAC6:2PQ7:7YET:EQBH
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://aw9phbpr.mirror.aliyuncs.com/
Live Restore Enabled: false

WARNING: devicemapper: usage of loopback devices is strongly discouraged for production use.
Use --storage-opt dm.thinpooldev to specify a custom block storage device.

2.docker安装完成后默认路径为 /var/lib/docker ,如果该路径的内存过小,则可以修改其目录;提供两种方法 ,以 /opt 目录为例

方法一:
首先停止docker服务
systemctl stop docker
备份原目录
cd /var/lib
cp -a docker docker.bak
拷贝docker目录到 /opt 下
cp -a docker /opt
删除 /var/lib 下的docker目录
rm -rf docker
建立软连接
ln -s /opt/docker docker
启动docker
systemctl start docker
使用 docker info 名利查看路径是否改变

方法二:
修改配置文件

cd /etc/systemd/system/multi-user.target.wants

vim docker.service

找到关键字ExecStart

ExecStart=/usr/bin/dockerd
在后面添加 –graph=/opt/docker

修改后为:
ExecStart=/usr/bin/dockerd –graph=/opt/docker
保存退出
重启docker
systemctl daemon-reload
systemctl start docker
然后查看docker信息看路径是否改变
docker info

到此docker服务安装完成,希望对您有所帮助!

你可能感兴趣的:(docker容器入门操作,后台运维)