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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | 创建并启动容器 # docker run [option ] IMAGE [:TAG | @DIGEST] [COMMAND ] [ARG...] option: 定制容器 网络 内存/Cpu限制 环境变量设置 数据卷挂载 # docker pull command :指定容器初始运行程序 Arg:指定参数 保持标准输入的打开状态 #docker run -i -t centos bash -i :保持标准输入的打开状态 -t :容器分配一个伪终端服务 Centos :镜像名 未指定 Tag,默认为latest bash:容器中要运行的命令 查看主机名: [root@904420c99d60 /]# hostname 904420c99d60 查看IP地址: [root@904420c99d60 /]# ip addr show eth0 73: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff inet 172.17.0.3/16 scope global eth0 inet6 fe80::42:acff:fe11:3/64 scope link valid_lft forever preferred_lft forever 查看进程: [root@904420c99d60 /]# ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 19:55 ? 00:00:00 /bin/bash root 16 1 0 19:56 ? 00:00:00 ps -ef [root@localhost ~]# docker run -d --name web -p 5000:5000 training/webapp --name web :将容器取名为web -d :设定为后台容器 -p :指定端口 列出运行中的容器: [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 234320cb5b8d centos "/bin/bash" 4 hours ago Up 4 hours furious_goodall d285d2331eca centos "/bin/bash" 2 days ago Up 2 days backstabbing_leakey 列出停止的容器: [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 25aef8640206 centos "/bin/bash" 2 minutes ago Exited (0) 2 minutes ago hopeful_noyce 904420c99d60 centos "/bin/bash" 10 minutes ago Exited (0) 8 minutes ago insane_babbage 234320cb5b8d centos "/bin/bash" 4 hours ago Up 4 hours furious_goodall d285d2331eca centos "/bin/bash" 2 days ago Up 2 days backstabbing_leakey 删除一个容器: [root@localhost ~]# docker rm 904420c99d60 904420c99d60 [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 25aef8640206 centos "/bin/bash" 4 minutes ago Exited (0) 4 minutes ago hopeful_noyce 234320cb5b8d centos "/bin/bash" 4 hours ago Up 4 hours furious_goodall d285d2331eca centos "/bin/bash" 2 days ago Up 2 days backstabbing_leakey 在已经运行中容器中额外进程: [root@localhost ~]# docker exec [root@localhost ~]# docker run -v -e -p -v :挂载数据卷 -e : 添加容器环境变量 -p :设置容器对外服务的端口 删除Docker容器: # docker rm $(docker ps -aq) -a :列出所有容器 -p : 只返回容器ID |