容器技术

四十五、Docker Compose-命令行基本使用

2021-12-31  本文已影响0人  InsaneLoafer

Note
运行docker-compose时需要在docker-compose.yml文件的目录下执行。否则找不到compose文件就会输出错误。
docker-compose.yml的文件名不能改变,否则需要额外指定-f文件运行。(与Dockerfile一致)

执行compose文件

后台运行

[root@localhost docker_exec]# docker-compose up -d
Starting docker_exec_flask-demo_1   ... done
Starting docker_exec_redis-server_1 ... done

查看日志

查看docker-compose的服务情况

[root@localhost docker_exec]# docker-compose ps
           Name                         Command               State                    Ports
--------------------------------------------------------------------------------------------------------------
docker_exec_flask-demo_1     flask run -h 0.0.0.0             Up      0.0.0.0:8080->5000/tcp,:::8080->5000/tcp
docker_exec_redis-server_1   docker-entrypoint.sh redis ...   Up      6379/tcp

停止docker-compose

[root@localhost docker_exec]# docker-compose stop
Stopping docker_exec_redis-server_1 ... done
Stopping docker_exec_flask-demo_1   ... done

删除已停止的通过compose创建的容器

[root@localhost docker_exec]# docker-compose rm
Going to remove docker_exec_redis-server_1, docker_exec_flask-demo_1
Are you sure? [yN] y
Removing docker_exec_redis-server_1 ... done
Removing docker_exec_flask-demo_1   ... done

Note
此命令不能删除通过compose创建的network以及images。

命名规则

[root@localhost docker_exec]# docker network ls
NETWORK ID     NAME                       DRIVER    SCOPE
1e6a14c63400   bridge                     bridge    local
8256654a8367   demo-network               bridge    local
7dd642472465   docker_exec_demo-network   bridge    local
d0763579887a   host                       host      local
6a03d63270a6   none                       null      local
[root@localhost docker_exec]# docker-compose -p myproject up -d
Creating network "myproject_demo-network" with the default driver
Creating myproject_redis-server_1 ... done
Creating myproject_flask-demo_1   ... done
上一篇下一篇

猜你喜欢

热点阅读