Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化,容器是完全使用沙箱机制,相互之间不会有任何接口。
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# yum install docker-io #yum 安装docker # service docker start #启动docker # docker search centos #搜索镜像 # docker pull centos #下载镜像 # docker pull hello-world # docker images #查看镜像 docker image ls # docker run centos /bin/echo "hello,world" hello,world # docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 84d4cf148816 centos "/bin/echo hello,worl" 10 seconds ago Exited (0) 8 seconds ago tiny_gates 1ca9b8360005 hello-world "/hello" 32 minutes ago Exited (0) 32 minutes ago mad_kare # docker run --name mydocker -it centos /bin/bash [root@3d8ff5dafbda /]# exit # docker attach 3d8ff5dafbda #进入退出容器 # docker start 3d8ff5dafbda 3d8ff5dafbda # docker inspect --format "{{.State.Pid}}" mydocker 14350 # nsenter --target 14350 --mount --uts --ipc --net --pid #yum install util-linux [root@3d8ff5dafbda /]# exit # brctl show #yum install bridge-utils bridge name bridge id STP enabled interfaces docker0 8000.0242f78f8f9e no vethd0a4b68 # docker run -d --name mynginx nginx # docker run -d -P --name mynginx nginx #-P随机端口 # docker run -d -p 8080:80 mynginx1 nginx #-p指定端口8080,80表示docker容器端口 # docker run -d -P --name mynginx nginx # netstat -tunlp Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1069/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2141/master tcp6 0 0 :::22 :::* LISTEN 1069/sshd tcp6 0 0 ::1:25 :::* LISTEN 2141/master tcp6 0 0 :::32768 :::* LISTEN 2468/docker-proxy tcp6 0 0 :::32769 :::* LISTEN 2475/docker-proxy # docker run -d -p 8080:80 --name mynginx1 nginx ac4075eddc63205a5c26f8e7c749ab195c90ee5c4376cf3e346efccc01fae63a # netstat -tunlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1069/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2141/master tcp6 0 0 :::8080 :::* LISTEN 2778/docker-proxy tcp6 0 0 :::22 :::* LISTEN 1069/sshd tcp6 0 0 ::1:25 :::* LISTEN 2141/master # docker run -it --name volume-test1 -h nginx -v /data nginx # docker run -it --name volume-test1 -h centos -v /data centos # touch /data/byrd # docker inspect -f {{.Volumes}} volume-test1 # docker inspect -f {{.}} volume-test1 {0xc8205e8000 [{617a073049308f765657f081f8699a15638b868ccab9482415db6d5be357541b /var/lib/docker/volumes/617a073049308f765657f081f8699a15638b868ccab9482415db6d5be357541b/_data /data local true }] 0xc820080000 0xc820080400} # docker run -it --name volume-test3 -h centos3 -v /opt:/opt centos # docker run -it --name volume-test5 --volumes-from volume-test1 centos # ls /data/ byrd |
0 1 2 3 4 5 6 7 8 9 10 11 |
[root@Docker ~]# docker search centos #搜索镜像 [root@Docker ~]# docker pull centos #下载镜像 [root@Docker ~]# docker images #查看镜像 [root@Docker ~]# docker run --nanem -h hostname #启动容器 [root@Docker ~]# docker stop CONTAINER ID #停止容器 [root@Docker ~]# docker ps #查看容器 [root@Docker ~]# docker exec | docker attach #进入容器 [root@Docker ~]# docker rm #删除容器 [root@Docker ~]# docker run -P #随机隐射 [root@Docker ~]# docker run -p hostPort:containerPort #指定端口隐射 [root@Docker ~]# docker run -p ip:hostPort:containerPort [root@Docker ~]# docker run -p ip::containerPort |
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!