docker 架构
docker使用C/S架构,Client通过接口与Server进程通信实现容器的构建、运行与发布。
获取镜像
[root@node1 ~]# docker image pull nginx:1.14-alpine
查看镜像列表
[root@node1 ~]# docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEnginx 1.14-alpine c5b6f731fbc0 4 weeks ago 17.7MB
启动容器
1、docker run(一步完成创建+启动)
[root@node1 ~]# docker run --name web01 -d nginx:1.14-alpine4795ee55e7e67e2224253917253b4e0b0fbb32da53d5a7869917bf034b83f0d3[root@node1 ~]# docker container lsCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES4795ee55e7e6 nginx:1.14-alpine "nginx -g 'daemon of…" 35 seconds ago Up 33 seconds 80/tcp web01
2、docker create + docker start
[root@node1 ~]# docker create --name web01 nginx:1.14-alpinefac034deb8a7fd6d49bb094ffcea4744f5b87e864c63dc508ea119a32d3fa475[root@node1 ~]# docker start web01web01[root@node1 ~]# docker container lsCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESfac034deb8a7 nginx:1.14-alpine "nginx -g 'daemon of…" 45 seconds ago Up 2 seconds 80/tcp web01
查看容器相关信息,获取分配的IPAddress并访问,可以看到一个简易的nginx搭建完毕。
[root@node1 ~]# docker inspect web01
删除镜像
[root@node1 ~]# docker rmi busyboxUntagged: busybox:latestUntagged: busybox@sha256:7964ad52e396a6e045c39b5a44438424ac52e12e4d5a25d94895f2058cb863a0Deleted: sha256:3a093384ac306cbac30b67f1585e12b30ab1a899374dabc3170b9bca246f1444Deleted: sha256:683f499823be212bf04cb9540407d8353803c25d0d9eb5f2fdb62786d8b95ead
删除容器
[root@node1 ~]# docker container lsCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES125c76bcd270 redis:4-alpine "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 6379/tcp kvstor1fac034deb8a7 nginx:1.14-alpine "nginx -g 'daemon of…" 20 minutes ago Up 20 minutes 80/tcp web01[root@node1 ~]# docker container ls -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES09e758d3d8a7 busybox:latest "sh" 28 seconds ago Exited (0) 24 seconds ago b1125c76bcd270 redis:4-alpine "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 6379/tcp kvstor1fac034deb8a7 nginx:1.14-alpine "nginx -g 'daemon of…" 20 minutes ago Up 20 minutes 80/tcp web01[root@node1 ~]# docker container rm b1b1[root@node1 ~]# docker container ls -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES125c76bcd270 redis:4-alpine "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 6379/tcp kvstor1fac034deb8a7 nginx:1.14-alpine "nginx -g 'daemon of…" 21 minutes ago Up 20 minutes 80/tcp web01
进入容器
[root@node1 ~]# docker container exec -it kvstor1 /bin/sh/data # /data # netstat -tlnActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN tcp 0 0 :::6379 :::* LISTEN