Docker-compose 常用命令

 2023-09-09 阅读 19 评论 0

摘要:命令 docker-compose --help build Build or rebuild services bundle Generate a Docker bundle from the Compose file config Validate and view the Compose file create Create services down Stop and remove containers, networks, images, and volumes events Receive

命令

 docker-compose --help

build               Build or rebuild services
bundle              Generate a Docker bundle from the Compose file
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-compose up -d nginx构建建启动nignx容器
docker-compose exec nginx bash登录到nginx容器中
docker-compose down删除所有nginx容器,镜像
docker-compose ps显示所有容器
docker-compose restart nginx重新启动nginx容器
docker-compose run --no-deps --rm php-fpm php -v在php-fpm中不启动关联容器,并容器执行php -v 执行完成后删除容器
docker-compose build nginx构建镜像
docker-compose build --no-cache nginx不带缓存的构建
docker-compose logs  nginx查看nginx的日志
docker-compose logs -f nginx查看nginx的实时日志
docker-compose config  -q验证(docker-compose.yml)文件配置,当配置正确时,不输出任何内容,当文件配置错误,输出错误信息。
docker-compose events --json nginx以json的形式输出nginx的docker日志
docker-compose pause nginx暂停nignx容器
docker-compose unpause nginx恢复ningx容器
docker-compose rm nginx删除容器(删除前必须关闭容器)
docker-compose stop nginx停止nignx容器
docker-compose start nginx启动nignx容器

详细解释

一 命令说明
build
构建或重新构建服务。服务被构建后会以project_service的形式标记,例如:composetest_db。


2 help
查看指定命令的帮助文档,该命令非常实用。docker-compose所有命令的帮助文档都可通过该命令查看。例如:

docker命令,
3 kill
通过发送SIGKILL信号停止指定服务的容器。

e.g.
docker-compose kill eureka

该命令也支持通过参数来指定发送的信号。

e.g.
docker-compose kill -s SIGINT


4 logs
查看服务的日志输出

docker菜鸟教程常用指令。 

5 port
打印绑定的公共端口。

e.g. docker-compose port eureka 8761



6 ps
列出所有的容器。

e.g. docker-compose ps

docker运行容器命令、

7 pull
下载服务镜像


8 rm
删除指定服务的容器。

e.g. docker-compose rm eureka


9 run
在一个服务上执行一个命令。

e.g. docker-compose run web bash


10 scale
设置指定服务运行容器的个数,以service=num的形式指定。

e.g. docker-compose scale user=3 movie=3


11 start
启动已停止的的容器。

e.g. docker-compose start eureka

 

12 stop
停止已运行的容器。
e.g. docker-compose stop eureka


13 up
构建、创建、重新创建、启动、连接服务的相关容器。所有服务都会启动,除非它们已经运行。
docker-compose up命令会聚合所有容器的输出,当命令退出时,所有容器都会停止。使用docker-compose up -d可在后台启动并运行所有的容器。
 

附录

简化命令

vi ~/.bashrc
alias dc='docker-compose'
source ~/.bashrc

 

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/4/29434.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息