运行“ docker-compose up”时出错
错误:yaml.scanner.ScannerError:此处不允许映射值 在“ ./docker-compose.yml”的第8行,第14列
我的docker撰写文件如下;
const mongoose = require ('mongoose');
const users = mongoose.model('users');
const admin = mongoose.model('admin');
const company = mongoose.model('company');
var MongoClient = require('mongodb').MongoClient;
module.exports.registerAdmin = (req, res, next) =>{
var company = new company();
company.companyName = req.body.companyName;
company.address = req.body.address;
company.contactDetails = req.body.contactDetails;
?? admin.email = req.body.email;
?? admin.firstName = req.body.firstName;
?? admin.lastName = req.body.lastName;
?? admin.phoneNumber = req.body.phoneNumber;
?? admin.designation = req.body.designation;
?? admin.role = "admin";
?? admin.id = req.body._id;
}
admin.save((err, doc) => {})
我试图通过更改卷路径之前的一些符号来进行尝试。
我想用postgres和redis图像组成docker文件。 我是Docker的初学者,而且是第一次。
答案 0 :(得分:0)
postgres:
image: postgres:9.4.21
environment:
POSTGRES_USER: myusername
POSTGRES_PASSWORD: myPass
ports:
-'5432:5432'
volumes:
- ~/.docker-volumes/mobydock/postgresql/data:/var/lib/postgresql/data
redis:
image: redis: 5.0.5
ports:
- '6379:6379'
volumes:
- ~/.docker-volumes/mobydock/redis/data:/var/lib/redis/data
mobydock:
build: .
command: gunicorn -b 0.0.0.0:8000 --reload --access-logfile - "mobydock.app:create_app()"
environment:
PYTHONUNBUFFERED: true
links:
- postgres
- redis
volumes:
- .:/mobydock
ports:
- '8000:8000'
yaml缩进敏感
答案 1 :(得分:0)
您的主要问题是不遵守YAML语法-如果您不熟悉YAML,则可以在网络上找到很多资源-例如:
-
:
)时,最好用引号(例如,image: "redis:5.0.5"
而不是image: redis: 5.0.5
您还存在一些与docker-compose语法相关的问题:
卷是不合适的列表,您最好使用绝对路径,而不要使用相对路径(在Compose中不要使用~/path
),例如:
volumes:
- /home/user/.docker-volumes/mobydock/redis/data:/var/lib/redis/data
在您的文件中,image
将作为volumes
的元素被读取,即您的缩进不正确。而不是使用:
# YAML will interpret image as being under the volume key
volumes:
- /home/user/.docker-volumes/mobydock/redis/data:/var/lib/redis/data
image: [...]
您应该具有:
# mind the space indentation !
volumes:
- /home/user/.docker-volumes/mobydock/redis/data:/var/lib/redis/data
image: [...]
大多数其他元素上也存在这种缩进错误,请检查Docker Compose语法以了解每个元素的顺序。
您可以使用as this one这样的YAML Linter来帮助解决这些YAML语法问题。
答案 2 :(得分:0)
volumes
是一个列表,因此您应该写:
volumes:
- ~/.docker-volumes/mobydock/redis/data:/var/lib/redis/data
此外,您的文件缩进不正确,应该这样写:
postgres:
image: "postgres:9.4.21"
environment:
POSTGRES_USER: myusername
POSTGRES_PASSWORD: myPass
ports:
-'5432:5432'
volumes:
- ~/.docker-volumes/mobydock/postgresql/data:/var/lib/postgresql/data
redis:
image: "redis:5.0.5"
ports:
- '6379:6379'
volumes:
- ~/.docker-volumes/mobydock/redis/data:/var/lib/redis/data
mobydock:
build: .
command: 'gunicorn -b 0.0.0.0:8000 --reload --access-logfile - "mobydock.app:create_app()"'
environment:
PYTHONUNBUFFERED: true
links:
- postgres
- redis
volumes:
- .:/mobydock
ports:
- '8000:8000'