互联网技术 / 互联网资讯 · 2023年10月31日

Docker Compose的端口和进程命令详解

Docker-Compose port命令可以打印公共端口以进行端口绑定,ps命令可以显示所有容器信息,默认显示Name、command、state、ports。

语法格式

Usage: port [options] SERVICE PRIVATE_PORT

Options:

–Protocol=Proto TCP 或者 UDP [默认: TCP]

–index=index 如果服务有多个实例,则为容器的索引[默认值:1]

例如输出绑定的公共端口

docker-compose port web 8080

语法格式

Usage: ps [options] [SERVICE…]

Options:

-q, –quiet 只显示ID

–services 显示服务

–filter KEY=VAL 通过一个属性过滤服务

-a, –all 显示所有停止容器(包括那些由运行命令)

例如列出容器

$ docker-compose ps

Name command State Ports

—————————————————————————————–

Mywordpress_db_1 docker-entrypoint.sh MySQLd Up (healthy) 3306/TCP

Mywordpress_wordpress_1 /entrypoint.sh Apache2-foR … RestaRting 0.0.0.0:8000->80/TCP

OpenMagic API

Need more than content? Move into the product flow.

If you are here for model access, pricing, developer docs, or the future API console, the dedicated product path now lives on api.openmagic.ai.

登录免费注册