1、首先拉取镜像
$ docker pull mongo
采用上述命令拉取镜像,
2、运行容器
docker run --name mongodb -p 27017:27017 -d mong
采用命令运行容器,但是运行完了之后会发现容器闪退了,docker logs 容器id查看了一下,
{"t":{"$date":"2023-05-25T10:46:13.173+00:00"},"s":"I", "c":"CONTROL", "id":23285, "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2023-05-25T10:46:13.173+00:00"},"s":"I", "c":"NETWORK", "id":4915701, "ctx":"main","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":17},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":17},"outgoing":{"minWireVersion":6,"maxWireVersion":17},"isInternalClient":true}}}
{"t":{"$date":"2023-05-25T10:46:13.174+00:00"},"s":"I", "c":"NETWORK", "id":4648601, "ctx":"main","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."}
{"t":{"$date":"2023-05-25T10:46:13.175+00:00"},"s":"I", "c":"REPL", "id":5123008,
发现是这么一堆看不懂,但是隐隐约约可以看到一些error,copy出来之后大概是如下
{
"t": {
"$date": "2023-05-25T10:46:13.186+00:00"
},
"s": "F",
"c": "CONTROL",
"id": 6384300,
"ctx": "main",
"msg": "Writing fatal message",
"attr": {
"message": "std::exception::what(): Operation not permitted\nActual exception type: std::system_error\n\n"
}
}
查看一下message,发现是通常是由于Docker容器内的权限问题导致的。
解决办法,加上参数--privileged就OK了,所以修改命令
docker run --privileged --name mongodb -p 27017:27017 -d mong
成功运行