Docker/Compose
< Docker
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
# Creates a three-container application based on Express, MariaDB, MongoDB, and Redis.
# MariaDB is used as a drop-in replacement for MySQL with a commitment to remaining open source.
#
# References:
# https://en.wikiversity.org/wiki/Docker/Express
# https://en.wikiversity.org/wiki/Docker/MySQL
# 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"
mariadb-server:
container_name: mariadb-server
image: mariadb
ports:
- "3306:3306"
mongo-server:
container_name: mongo-server
image: mongo
ports:
- "27017:27017"
redis-server:
container_name: redis-server
image: redis
ports:
- "6379:6379"
Try It
Online Free
- 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:
touch docker-compose.ymltouch Dockerfiletouch app.js
- Use the
Editorbutton to edit the files and save the contents into each respective file. Use thedocker-compose.ymlfile above and theDockerfileandapp.jsfiles from Docker/Express. - Run the following commands:
docker-compose up
- In the top window, select the
Open Portbutton and enter3000to connect to the running server.
On Your Own System
- Install Docker Desktop or the Docker Engine.
- Save the file above and from Docker/Express into a new
Docker Expressfolder:docker-compose.ymlDockerfileapp.js
- At a command prompt, change to the
Docker Expressfolder and then run the following command:docker-compose up
- Open a web browser to connect to the running server: