1、用yum源安装
查看是否安装命令
yum list installed | grep docker
安装docker命令
yum -y install docker
-y表示不询问安装
启动docker命令
systemctl start docker
查看docker服务状态
systemctl status docker
2、离线安装模式
上传或者下载安装包
wget https://download.docker.com/linux/static/stable/x86_64/docker-18.06.3-ce.tgz
解压 复制到目录
tar -zxvf docker-18.06.3-ce.tgz
cp docker/* /usr/bin/
在/etc/systemd/system/目录下新增docker.service文件 这样可以将docker注册为service服务
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --selinux-enabled=false --insecure-registry=127.0.0.1
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
授权
chmod +x /etc/systemd/system/docker.service
启动docker
重新加载配置文件 systemctl daemon-reload
启动systemctl start docker
systemctl daemon-reload
systemctl start docker
设置开机启动
systemctl enable docker.service
3、docker命令
进入镜像命令docker exec -it 89c5b9c81e74 bash
启动容器 docker run --name nginx
停止容器 docker stop nginx
删除容器 docker rm nginx
信息查看 docker info
[root@10-9-25-182 ~]# docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 18.06.3-ce
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
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: 468a545b9edcd5932818eb9de8e72413e616e86e
runc version: a592beb5bc4c4092b1b1bac971afed27687340c5
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 4.18.0-147.5.1.el8_1.x86_64
Operating System: CentOS Linux 8 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 1.701GiB
Name: 10-9-15-182
ID: 3VIG:ANXE:JRSP:OXY6:QJJG:UI4F:XFFE:GJO2:KRKX:INJJ:NTPN:BTRK
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.1
127.0.0.0/8
Live Restore Enabled: false
备注:
如果报错找不到 docker.service
Failed to start docker.service: Unit docker.service not found.
参考这篇文章 https://blog.csdn.net/qiao_xinxin/article/details/114943904
注意:本文归作者所有,未经作者允许,不得转载