[英]How to create service in Docker Swarm using prebuilt local image
I have created 3 nodes, 1 as manager and other 2 as workers in Docker Swarm
as shown below我在
Docker Swarm
中创建了 3 个节点,1 个作为经理,另外 2 个作为工作人员,如下所示
Now when I try to create service (on manager node) using local image app1:latest
I get an error (mentioned below).现在,当我尝试使用本地图像
app1:latest
创建服务(在管理器节点上)时,出现错误(如下所述)。
$ sudo docker service create --name app1 -p 5001:5000 app1:latest
image app1:latest could not be accessed on a registry to record
its digest. Each node will access app1:latest independently,
possibly leading to different nodes running different
versions of the image.
i6s8hyzzuxx35enl2j0xd3ef9
overall progress: 0 out of 1 tasks
1/1: No such image: app1:latest
On the other hand if I use public images from Docker Hub
(for example nginx
image) then I can easily create the service.另一方面,如果我使用来自
Docker Hub
的公共图像(例如nginx
图像),那么我可以轻松创建服务。
How can I use prebuilt local image to create the service?如何使用预建的本地镜像来创建服务?
Below is the Dockerfile
and app.py
file used to build the image app1:latest
下面是用于构建图像
app1:latest
的Dockerfile
和app.py
文件
Dockerfile Dockerfile
FROM ubuntu:18.04
RUN apt-get update \
&& apt-get install -y apt-utils \
python3.6 \
python3-pip
WORKDIR /app
COPY . /app
RUN pip3 install -r requirements.txt
ENTRYPOINT ["python3"]
CMD ["app.py"]
app.py应用程序.py
from flask import Flask
from flask import jsonify
app = Flask(__name__)
@app.route('/')
def index():
return jsonify('App #1')
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)
I have followed some articles and video tutorials about Docker Swarm
but they all are using public image from Docker Hub to create the service我关注了一些关于
Docker Swarm
的文章和视频教程,但它们都使用来自 Docker Hub 的公共图像来创建服务
Unless you "push" your image to a docker registry (either docker hub or a private one ), the image you build only exists on your local machine (and not accessible to the swarm nodes).除非您将映像“推送”到 docker 注册表(docker 集线器或私有集线器),否则您构建的映像仅存在于本地计算机上(集群节点无法访问)。
So, you either need to push to docker hub, or run your own registry.因此,您要么需要推送到 docker 集线器,要么运行自己的注册表。 In the latter case, make sure the registry host is reachable from swarm nodes.
在后一种情况下,请确保注册表主机可以从 swarm 节点访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.