[root@chy ~]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f98ab40c32a6 centos
"bash"
10 seconds ago Up 4 seconds heuristic_torvalds
c06361830af1 centos7_1
"/bin/sh -c '/usr/..."
About a minute ago Up About a minute 0.0.0.0:8080->80
/tcp
root_app1_1
726da06d12c8 centos7_1
"tail -f /etc/passwd"
21 minutes ago Up 20 minutes 80
/tcp
root_app2_1
1101ab2618a4 centos7_1
"/bin/sh -c '/usr/..."
18 hours ago Up 18 hours 0.0.0.0:81->80
/tcp
hopeful_pasteur
[root@chy ~]
version:
"2"
services:
app1:
image: centos_nginx
ports:
-
"8080:80"
networks:
-
"net1"
volumes:
-
/data/
:
/data
app2:
image: centos_with_nettool
networks:
-
"net2"
volumes:
-
/data/
:
/data1
entrypoint:
tail
-f
/etc/passwd
networks:
net1:
driver: bridge
net2:
driver: bridge
参数详解:
version:
"2"
//
版本为2版本
services:
//
相关容器或者镜像操作
app1:
//app1
对应的是容器1的信息,这里需要注意是要运行的容器的名称
image: centos7_1
///images
的名字
ports:
//
映射端口
-
"8080:80"
//
映射宿主机8080对应容器的80端口
networks:
//
网络(默认是bridge模式)
-
"net1"
//
下面定义的net1(要是需要pipwork怎么办?官方不支持,就只能在写shell然后在 driver后面 定义none)
volumes:
//-v
的参数指定
-
/data/
:
/data
//
目录映射
app2:
image: centos
networks:
-
"net2"
volumes:
-
/data/
:
/data1
entrypoint:
tail
-f
/etc/passwd
///
还是老问题BUG 为了不让执行后关闭,我们使用这条命令
networks:
//
这里就是如上net1定义的网络模式
net1:
driver: bridge
net2:
driver: bridge
[root@chy ~]
Recreating root_app2_1 ...
Recreating root_app2_1
Recreating root_app2_1 ...
done
[root@chy ~]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9646c0a40ae1 centos
"tail -f /etc/passwd"
7 minutes ago Up 7 minutes root_app2_1
f98ab40c32a6 centos
"bash"
8 minutes ago Up 7 minutes heuristic_torvalds
c06361830af1 centos7_1
"/bin/sh -c '/usr/..."
9 minutes ago Up 9 minutes 0.0.0.0:8080->80
/tcp
root_app1_1
1101ab2618a4 centos7_1
"/bin/sh -c '/usr/..."
18 hours ago Up 18 hours 0.0.0.0:81->80
/tcp
hopeful_pasteur
[root@chy ~]