Docker 安装和使用
1、在Ubuntu上安装docker,这里使用的版本是:Ubuntu18.04
安装apt-transport-https等软件包支持HTTPS协议源:[email protected]:~$ sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
添加源的gpg密钥:
[email protected]:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
OK
确认导入密钥:
[email protected]:~$ sudo apt-key fingerprints 0EBFCD88
pub rsa4096 2017-02-22 [SCEA]
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid [ unknown] Docker Release (CE deb) <[email protected]>
sub rsa4096 2017-02-22 [S]
获取当前操作系统的代号:
一般情况下,Ubuntu 16.04 LTS代号为xenial, Ubuntu 18.04 LTS代号为bionic
[email protected]:~$ lsb_release -cs
bionic
添加官方稳定版软件源:
[email protected]:~$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
添加后需要更新apt软件包缓存:
[email protected]:~$ sudo apt-get update
开始安装docker,安装成功之后、会自动启动docker服务
[email protected]:~$ sudo apt-get install -y docker-ce
2、在centos安装docker、这里使用的版本为centos 7.5,需要提前配置好epel源、获取docker的repo文件和安装docker
[[email protected] ~]# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/
[[email protected] ~]# yum -y install docker-ce
使用阿里云加速器、阿里云的镜像地址为 http://dev.aliyun.com 需要注册,使用自己的加速地址即可
[[email protected] ~]# mkdir -p /etc/docker
[[email protected] docker]# vim daemon.json
{
"registry-mirrors": ["https://xxxxxx.mirror.aliyuncs.com"]
}
在启动之前需要改下docker的启动服务加一项iptables规则要不然启动之后forwar链上默认被改成DROP
[[email protected] docker]# vim /usr/lib/systemd/system/docker.service
ExecStartPost=/usr/sbin/iptables -P FORWARD ACCEPT
重载文件、并启动docker服务
[[email protected] docker]# systemctl daemon-reload
[[email protected] docker]# systemctl restart docker
查看docker的信息
[[email protected] ~]#docker info
Containers: 6
Running: 6
Paused: 0
Stopped: 0
Images: 5
Server Version: 18.06.1-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: 69663f0bd4b60df09991c08812a60108003fa340
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-862.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.779GiB
Name: node7.dklwj.com
ID: OST6:BVR7:UBAN:ACCI:YKPX:RLEM:DXKQ:QQPI:LYSY:PIVO:EUUA:4PQR
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://xxxxxxxxx.mirror.aliyuncs.com/
Live Restore Enabled: false
原文地址:http://blog.51cto.com/dklwj/2316745
时间: 2024-10-08 23:46:53