安装并启动docker
[root@server1 docker]# rm -f docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm docker-ce-18.09.5-3.el7.x86_64.rpm containerd.io-1.2.5-3.1.el7.x86_64.rpm docker-ce-cli-18.09.5-3.el7.x86_64.rpm
[root@server1 docker]# ls
container-selinux-2.21-1.el7.noarch.rpm
docker-ce-18.06.1.ce-3.el7.x86_64.rpm
libsemanage-2.5-8.el7.x86_64.rpm
libsemanage-python-2.5-8.el7.x86_64.rpm
pigz-2.3.4-1.el7.x86_64.rpm
policycoreutils-2.5-17.1.el7.x86_64.rpm
policycoreutils-python-2.5-17.1.el7.x86_64.rpm
[root@server1 docker]# yum install * -y
[root@server1 docker]# systemctl start docker
[root@server1 docker]# docker info
搭建2048游戏
导入game2048镜像
[root@server1 ~]# docker load -i game2048.tar ##导入镜像
[root@server1 ~]# docker images ##查看镜像信息
[root@server1 ~]# docker run -d -p 80:80 --name vm1 game2048 ##创建容器 并做端口映射
查看容器信息
[root@server1 ~]# docker inspect vm1
在浏览器上输入本机IP
导入运行ubuntu
[root@server1 images]# docker load -i ubuntu.tar
[root@server1 images]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
game2048 latest 19299002fdbe 2 years ago 55.5MB
ubuntu latest 07c86167cdc4 3 years ago 188MB
[root@server1 images]# docker run -it --name vm2 ubuntu
root@6a54b61dc0db:/# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
root@6a54b61dc0db:/#
查看桥接
[root@server1 images]# yum install bridge-utils-1.5-9.el7.x86_64
[root@server1 images]# brctl show
bridge name bridge id STP enabled interfaces
docker0 8000.0242f9a71500 no veth16e1ffe
vethe517671
[root@server1 images]# docker inspect vm1
[root@server1 images]# docker inspect vm2
如何修改容器内的信息
搭建ubuntu
[root@server1 images]# docker attach vm2 ##连接容器
[root@server1 images]# docker stop vm2 ##停止容器
vm2
[root@server1 images]# docker rm vm2 ##删除容器
vm2
[root@server1 images]# docker run -it --name vm2 ubuntu
root@99b7d5ab17bd:/# touch file{1..10}
root@99b7d5ab17bd:/# ls
bin etc file2 file5 file8 lib mnt root srv usr
boot file1 file3 file6 file9 lib64 opt run sys var
dev file10 file4 file7 home media proc sbi