Docker Compose is a tool for defining and running multi-container Docker applications. It uses YAML files to configure the application's services and performs the creation and start-up process of all the containers with a single command. The docker-compose CLI utility allows users to run commands on multiple containers at once, for example, building images, scaling containers, running containers that were stopped, and more. The docker-compose.yml file is used to define an application's services and includes various configuration options.
docker-compose.yml[edit | edit source]
# Creates a three-container application based on Express, MongoDB, and Redis. # # References: # https://en.wikiversity.org/wiki/Docker/Express # https://en.wikiversity.org/wiki/Docker/MongoDB # https://en.wikiversity.org/wiki/Docker/Redis # https://en.wikiversity.org/wiki/Server-Side_Scripting version: "2" services: express-server: container_name: express-server restart: always build: . ports: - "3000:3000" mongo-server: container_name: mongo-server image: mongo ports: - "27017:27017" redis-server: container_name: redis-server image: redis ports: - "6379:6379"
Try It[edit | edit source]
Online Free[edit | edit source]
- Use Play with Docker. Create an account and/or log in.
- Start an interactive session and add a new instance.
- In the terminal window, enter the following commands:
- Use the
Editorbutton to edit the files and save the contents into each respective file. Use the
docker-compose.ymlfile above and the
app.jsfiles from Docker/Express.
- Run the following commands:
- In the top window, select the
Open Portbutton and enter
3000to connect to the running server.
On Your Own System[edit | edit source]
- Install Docker Desktop or the Docker Engine.
- Save the file above and from Docker/Express into a new
- At a command prompt, change to the
Docker Expressfolder and then run the following command:
- Open a web browser to connect to the running server: