I have created 3 nodes, 1 as manager and other 2 as workers in Docker Swarm
as shown below
Now when I try to create service (on manager node) using local image app1:latest
I get an error (mentioned below).
$ 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.
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
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
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
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).
So, you either need to push to docker hub, or run your own registry. In the latter case, make sure the registry host is reachable from swarm nodes.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.