本文共 2148 字,大约阅读时间需要 7 分钟。
centos7
yum -y install docker
docker加速
1 | curl -sSL https: //get .daocloud.io /daotools/set_mirror .sh | sh -s http: //224ac393 .m.daocloud.io |
4.systemctl start docker
1 2 3 4 5 6 7 8 9 10 | [root@web01 ~] # systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded ( /usr/lib/systemd/system/docker .service; enabled; vendor preset: disabled) Active: active (running) since Thu 2016-12-22 20:25:00 CST; 1 weeks 5 days ago Docs: http: //docs .docker.com Main PID: 799 (docker-current) Memory: 39.1M CGroup: /system .slice /docker .service ├─ 799 /usr/bin/docker-current daemon --registry-mirror=http: //224ac393 .m.daocloud.io -- exec -opt native.cg... └─28516 docker-proxy -proto tcp -host-ip 59.110.25.215 -host-port 88 -container-ip 192.168.0.2 -container-p.. |
4.拉公共的镜像
1 2 3 4 5 6 7 8 | docker pull centos docker pull nginx docker save -o nginx. tar .gz nginx docker save -o centos. tar .gz centos docker load --input nginx. tar .gz docker load --input centos. tar .gz |
5.启动一个nginx
1 2 3 4 5 | docker run -d --name mynginx -p 59.110.25.215:88:80 nginx 说明:基于nginx镜像启动一个mynginx的容器 本机端口 88 端口对应容器 80 端口 浏览: 指定多个端口: docker run -d --name mynginx -p 59.110.25.215:88:80 -p 59.110.25.215:443:443 nginx |
6.查看对应的端口
1 2 3 4 5 | docker port mynginx [root@web01 ~] # docker port mynginx 80 /tcp -> 59.110.25.215:88 [root@web01 ~] # |
7.进入docker容器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #!/bin/bash # Use nsenter to access docker docker_in(){ NAME_ID=$1 PID=$(docker inspect -f "{ { .State.Pid }}" $NAME_ID) nsenter -t$PID -m -u -i -n -p } docker_in $1 上述的脚本就是dockerin.sh [root@web01 ~] # docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1f3d2f356995 nginx "nginx -g 'daemon off" 18 minutes ago Up 18 minutes 443 /tcp , 59.110.25.215:88->80 /tcp mynginx [root@web01 ~] # bash dockerin.sh 1f3d2f356995 root@1f3d2f356995:/ # |
8.进入容器以后修改容器内部的东西
1 2 3 4 | root@1f3d2f356995: /usr/share/nginx/html # echo "hello everyone" > index.html root@1f3d2f356995: /usr/share/nginx/html # pwd /usr/share/nginx/html root@1f3d2f356995: /usr/share/nginx/html # |