例子:
docker run -d --name game -p 8080:80 game2048
映射到系统的8080端口
http://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/
yum install container-selinux-2.21-1.el7.noarch.rpm docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm libsemanage-python-2.5-8.el7.x86_64.rpm libsemanage-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
安装游戏
systemctl start docker
docker load -i game2048.tar
docker run -d --name game -p 8080:80 game2048
-d打入后台 run开启 --name 创建名称
网上查询安装的东西
docker search nginx
只有官方创建的没有作者名字
默认容器的网络是内部的
docker ps 查看容器
docker inspect game
与物理机通信都是通过桥接
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
inet6 fe80::42:9aff:fe1d:d0a1 prefixlen 64 scopeid 0x20<link>
ether 02:42:9a:1d:d0:a1 txqueuelen 0 (Ethernet)
RX packets 60 bytes 112780 (110.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 75 bytes 10650 (10.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
如何将index.html放入自己的nginx 容器中 vm1
docker inspect vm1
docker history vm1
docker container exec -it vm1 /bin/bash
获取vm1容器下的bash命令终端
cd /usr/share/nginx/html 找到发布目录
exit
docker cp index.html vm1:/usr/share/nginx/html/
就可以看到了
还有一种方式
docker rm-f vm1
docker run -d --name vm1 -v /tmp/html/:/usr/share/nginx/html/
直接挂载后,物理机更改发布目录的配置,容器也会自动更新
docker run -it --name vm2 rhel7 /bin/bash