Docker Compose is really useful when we don’t have the development environment setup on our local machine to run all parts of the application to test or we want to run all parts of the application with one command. For example, if you want to run Vue.js and nodes express server on different ports and you need a single command to run you can accomplish that with Docker Compose.
当我们没有在本地计算机上设置开发环境来运行应用程序的所有部分进行测试或者我们想要使用一个命令来运行应用程序的所有部分时,Docker Compose真的很有用。 例如,如果要运行Vue.js,并且节点在不同的端口上表示服务器,并且需要单个命令来运行,则可以使用Docker Compose来完成。
In this post, we will see what is Docker Compose and how we can do the local development with Docker Compose and advantages as well.
在本文中,我们将了解什么是Docker Compose,以及我们如何利用Docker Compose进行本地开发及其优势。
What is Docker Compose
什么是Docker Compose
Example Project
示例项目
Run Without Docker Compose
在没有Docker Compose的情况下运行
With Docker Compose
使用Docker Compose
Communication Between Services
服务之间的沟通
Summary
摘要
Conclusion
结论
什么是Docker Compose (What is Docker Compose)
Docker-compose is a tool that is used for multi-container applications in a single host. As we can see in the following figure, we can run multi containers as services in the single host with the help of docker-compose.yaml.
Docker-compose是一种用于单个主机中的多容器应用程序的工具。 如下图所示,借助于docker-compose.yaml ,我们可以在单个主机中将多个容器作为服务运行。
Once we install docker-compose, basically, we need to follow these three steps
一旦安装了docker-compose,基本上,我们需要遵循以下三个步骤
- Define Dockerfile for the service/container 为服务/容器定义Dockerfile
Define docker-compose.yaml file with all the services, ports and other details
使用所有服务,端口和其他详细信息定义docker-compose.yaml文件
Run this command docker-compose up
运行此命令docker-compose up
Here are some useful commands
这是一些有用的命令
// create and start containers
docker-compose up// start services with detached mode
docker-compose -d up// start specific service
docker-compose up <service-name>// list images
docker-compose images// list containers
docker-compose ps// start service
docker-compose start// stop services
docker-compose stop// display running containers
docker-compose top// kill services
docker-compose kill// remove stopped containers
docker-compose rm// stop all contaners and remove images, volumes
docker-compose down
示例项目 (Example Project)
This is a simple project which demonstrates developing and running Vue application with NodeJS. We have a simple app in which we can add users, count, and display them at the side, and retrieve them whenever you want.
这是一个简单的项目,演示了如何使用NodeJS开发和运行Vue应用程序。 我们有一个简单的应用程序,可以在其中添加用户,计数并在侧面显示它们,并在需要时检索它们。
![Image for post](https://miro.medium.com/freeze/max/9999/0*wc5iLD_wVYPkOs7w.gif)