Docker/Compose
Appearance
< 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
[edit | edit source]# 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
[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:
touch docker-compose.yml
touch Dockerfile
touch app.js
- Use the
Editor
button to edit the files and save the contents into each respective file. Use thedocker-compose.yml
file above and theDockerfile
andapp.js
files from Docker/Express. - Run the following commands:
docker-compose up
- In the top window, select the
Open Port
button and enter3000
to 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
Docker Express
folder:docker-compose.yml
Dockerfile
app.js
- At a command prompt, change to the
Docker Express
folder and then run the following command:docker-compose up
- Open a web browser to connect to the running server: