一.docker容器简介
1.操作系统共享宿主机 2.几乎无性能损耗 3.轻量,灵活迁移 4.安全隔离 5.部署快速,秒级 6.运行密度大,单机支持上千容器
二.安装部署docker
1.下载以下安装包并开启容器
[root@server1 ~]# ls
containerd.io-1.2.13-3.2.el7.x86_64.rpm docker-ce-19.03.12-3.el7.x86_64.rpm
container-selinux-2.77-1.el7.noarch.rpm docker-ce-cli-19.03.12-3.el7.x86_64.rpm
[root@server1 ~]# yum install -y *
[root@server1 ~]# systemctl start docker
[root@server1 ~]# systemctl enable --now docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service
2.编辑docker的配置文件,打开桥接网络接口
##查看容器的基本信息,发现有两个警告,需开启桥街网络接口
[root@server1 ~]# docker info
Client:
Debug Mode: false
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 19.03.12
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 ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-957.el7.x86_64
Operating System: Red Hat Enterprise Linux Server 7.6 (Maipo)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 1.952GiB
Name: server1
ID: ZI4J:DXKW:2EOG:IZGR:SSRC:33BV:EW2W:NVEK:PF2I:446C:F5X6:R4SH
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
[root@server1 ~]# cd /etc/sysctl.d
[root@server1 sysctl.d]# vim docker.conf
[root@server1 sysctl.d]# cat docker.conf
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
[root@server1 sysctl.d]# sysctl --system
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
三.导入镜像,并在此镜像上运行一个容器
[root@server1 ~]# docker load -i game2048.tar
011b303988d2: Loading layer 5.05MB/5.05MB
36e9226e74f8: Loading layer 51.46MB/51.46MB
192e9fad2abc: Loading layer 3.584kB/3.584kB
6d7504772167: Loading layer 4.608kB/4.608kB
88fca8ae768a: Loading layer 629.8kB/629.8kB
Loaded image: game2048:latest
[root@server1 ~]# docker run -d --name demo -p 80:80 game2048
950e8e49c288f172cb5614a4b235f10a8606903f72ec2592651a654e0a23a44f
[root@server1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
950e8e49c288 game2048 "/bin/sh -c 'sed -i …" 14 seconds ago Up 13 seconds 0.0.0.0:80->80/tcp, 443/tcp demo
四.docker基本操作
1.查找镜像
[root@server1 ~]# docker search nginx
[root@server1 ~]# docker search busybox
2.查看主机导入的所有镜像
[root@server1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest edabd795951a 2 days ago 1.22MB
nginx latest 4bb46517cac3 2 weeks ago 133MB
game2048 latest 19299002fdbe 3 years ago 55.5MB