如果我以分离模式运行容器,则它将按预期运行,如下所示。但是,如果我以交互方式运行它,则端口9200并未按预期分配给elasticsearch。
# docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -d elasticsearch:7.3.1
650a7ec48812325631183d1c9d53e7d6d81ab296bfe9d8076593471aede4fa43
# docker exec -it 650a7ec48812325631183d1c9d53e7d6d81ab296bfe9d8076593471aede4fa43 bash
[root@650a7ec48812 elasticsearch]# curl http://localhost:9200/
{
"name" : "650a7ec48812",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "soPITNmpTimq7KJApj9s9A",
"version" : {
"number" : "7.3.1",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "4749ba6",
"build_date" : "2019-08-19T20:19:25.651794Z",
"build_snapshot" : false,
"lucene_version" : "8.1.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
根据我的理解,分离和交互/终端模式是相同的(一个在同一线程中继续,而另一个在创建新线程)。有人可以解释这两种运行docker image模式的区别吗?
# docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -it elasticsearch:7.3.1 bash
# curl http://localhost:9200/
curl: (7) Failed to connect to ::1: Cannot assign requested address
答案 0 :(得分:1)
这是因为自您覆盖elasticsearch
以来CMD
尚未启动,容器将运行到bash
,在两种模式之间没有任何关系...