文章插图
以下方式的网络声明创建网络时会使用默认的名称:"工程名称_网络条目名称" , 网络模式默认为 bridge 。
# 描述 Compose 文件的版本信息 version: "3.8" # 定义服务 , 可以多个 services: nginx: image: nginx container_name: mynginx ports: - "80:80" networks: # 配置容器连接的网络 , 引用顶级 networks 下的条目 nginx-net: ? # 定义网络 , 可以多个 networks: nginx-net: # 一个具体网络的条目名称
文章插图
以下方式的网络声明创建网络时会使用自定义的名称 , 还可以通过 driver 选择网络模式 , 默认为 bridge 。
# 描述 Compose 文件的版本信息 version: "3.8" # 定义服务 , 可以多个 services: nginx: image: nginx container_name: mynginx ports: - "80:80" networks: # 配置容器连接的网络 , 引用顶级 networks 下的条目 nginx-net: ? # 定义网络 , 可以多个 networks: nginx-net: # 一个具体网络的条目名称 name: nginx-net # 网络名称 , 默认为"工程名称_网络条目名称" driver: bridge # 网络模式 , 默认为 bridge
文章插图
Compose 常用命令
官方文档:https://docs.docker.com/compose/reference/overview/
为了更熟练的使用 Compose , 以下常用命令大家多多练习 , 方可熟能生巧 。
docker-compose [-f <arg>...] [options] [COMMAND] [ARGS...]
部分命令选项如下:- -f , --file:指定使用的 Compose 模板文件 , 默认为 docker-compose.yml , 可以多次指定 , 指定多个 yml;
- -p, --project-name:指定工程名称 , 默认使用 docker-compose.yml 文件所在目录的名称;
- -v:打印版本并退出;
- --log-level:定义日志等级(DEBUG, INFO, WARNING, ERROR, CRITICAL) 。
help
docker-compose -help 查看帮助 。
[root@localhost ~]# docker-compose -help Define and run multi-container applications with Docker. ? Usage: docker-compose [-f <arg>...] [options] [COMMAND] [ARGS...] docker-compose -h|--help ? Options: -f, --file FILE Specify an alternate compose file (default: docker-compose.yml) -p, --project-name NAME Specify an alternate project name (default: directory name) -c, --context NAME Specify a context name --verbose Show more output --log-level LEVEL Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL) --no-ansi Do not print ANSI control characters -v, --version Print version and exit -H, --host HOST Daemon socket to connect to ? --tls Use TLS; implied by --tlsverify --tlscacert CA_PATH Trust certs signed only by this CA --tlscert CLIENT_CERT_PATHPath to TLS certificate file --tlskey TLS_KEY_PATH Path to TLS key file --tlsverify Use TLS and verify the remote --skip-hostname-check Don't check the daemon's hostname against the name specified in the client certificate --project-directory PATH Specify an alternate working directory (default: the path of the Compose file) --compatibility If set, Compose will attempt to convert keys in v3 files to their non-Swarm equivalent --env-file PATH Specify an alternate environment file ? Commands: build Build or rebuild services config Validate and view the Compose file create Create services down Stop and remove containers, networks, images, and volumes events Receive real time events from containers exec Execute a command in a running container help Get help on a command images List images kill Kill containers logs View output from containers pause Pause services port Print the public port for a port binding ps List containers pull Pull service images push Push service images restart Restart services rm Remove stopped containers run Run a one-off command scale Set number of containers for a service start Start services stop Stop services top Display the running processes unpause Unpause services up Create and start containers version Show the Docker-Compose version information
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Docker-For-Pentest的渗透测试镜像推荐
- Docker 安装es和kibana踩坑记录
- Calico网络架构
- linux操作系统上安装docker
- docker 镜像的使用
- 用docker搭建 drogon 环境 世界最快WEB
- 用这个Python的Docker正式版镜像,你也能成容器高玩
- k8s版本平滑升级
- 如何按照条件向Spring容器中注册bean?这次我懂了
- Docker 的前世今生