table of Contents
1. Introduction to docker-compose
yaml
The design goal of yaml language is to facilitate human reading and writing. It is essentially a universal data serialization format. The
basic syntax is as follows
- Tab key indentation is not supported, use spaces for indentation
- Usually indented 2 spaces at the beginning
- Indent 1 space after the character, such as colon, comma, horizontal bar
- Use single quotes if it contains special characters
- # Indicates a comment
- Boolean values must be enclosed in quotation marks
There are three supported data structures
- Object: A collection of key-value pairs, also known as a map/hash/dictionary
- Array: A set of values arranged in order, also known as sequence/list
- Scalar: a single, indivisible value
Second, the deployment of compose
You need to deploy the docker environment before deploying compose
yum install docker-ce -y
Download compose
mkdir compose_nginx
cd compose_nginx
curl -L https://github.com/docker/compose/releases/download/1.21.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
It’s not easy to download and drag me the package extraction code: zqzq; docker-compose
cp -p docker-compose /usr/local/bin/
chmod +x /usr/local/bin/docker-compose
mkdir /root/compose_nginx
Three, create a container (take nginx as an example)
1. Write a yml file
vim /root/compose_nginx/docker-compose.yml
version: '3'
services:
nginx:
hostname: nginx
build:
context: ./nginx
dockerfile: Dockerfile
ports:
- 1216:80
- 1217:443
networks:
- cluster
volumes:
- ./wwwroot:/usr/local/nginx/html
networks:
cluster:
2. Put in relevant documents
mkdir nginx
mkdir wwwroot
echo "this is nginx" > wwwroot/index.html
yum -y install tree
tree ./
3. Execute the yml file to create a container
docker-compose -f docker-compose.yml up -d