简体   繁体   English

如何将本地构建部署到虚拟机中的docker swarm?

[英]can I deploy local build to docker swarm in virtual machine?

I am learning Docker and trying to follow the Docker tutorial and am in step 4 here . 我正在学习Docker并尝试遵循Docker教程,并且在此处的第4步。

Basically in this step, we are creating 2 VMs for docker swarm: 1 as swarm manager and 1 as swarm worker. 基本上,在此步骤中,我们将为docker swarm创建2个VM:1个为swarm管理器,1个为swarm worker。

I think it pulls docker-hub pushed image to the virtual machines to get the service working in swarm. 我认为它会将docker-hub推送的映像拉到虚拟机,以使服务在群中工作。 Problem is I am not pushing my built image to docker hub. 问题是我没有将构建的映像推送到docker hub。

My question is, can I use local build to deploy to the swarm VM? 我的问题是,我可以使用本地构建将其部署到群集VM吗?

I tried to change image line the example docker-compose.yml to build like so: 我试图改变image线的例子docker-compose.ymlbuild像这样:

version: "3"
services:
  web:
    # replace username/repo:tag with your name and image details
    # image: friendlyhello
    build: .
    deploy:
      replicas: 5
      resources:
        limits:
          cpus: "0.1"
          memory: 50M
      restart_policy:
        condition: on-failure
    ports:
      - "4000:80"
    networks:
      - webnet
networks:
  webnet:

it of course does not work, which is why I am asking if there is a way to do this? 它当然不起作用,这就是为什么我问是否有办法做到这一点?

You can create a local registry on the vm or your local machine and push/pull images from local repo 您可以在vm或本地计算机上创建本地注册表,并从本地存储库推/拉映像

docker run -d -p 5000:5000 --restart=always --name registry registry:2

Then name/tag your images using 然后使用命名/标记您的图像

localhost:5000/Image_Name:Tag

Then push images using 然后使用

docker push localhost:5000/Image_Name:Tag

This will let you save your images in a local registry that your swarm can use without pushing to dockerhub 这将使您将图像保存在您的集群可以使用的本地注册表中,而无需推送到dockerhub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用docker-machine,如何不使用swarm或compose在ec2实例上构建本地Dockerfile? - Using docker-machine, how can I build a local Dockerfile on an ec2 instance without using swarm or compose? 如何从本地开发机器部署到 Docker Swarm? - How to deploy to a Docker Swarm from a local dev machine? 如何使用docker-machine引导50台机器? - How can I boot a swarm of 50 machines with docker-machine? 如何在docker swarm模式下指定机器? - How can I specify the machine in docker swarm mode? 我可以在虚拟机中运行 Docker 吗? - Can I run Docker in a Virtual Machine? 我无法通过本地机器上的 docker compose 在远程服务器上部署应用程序(SSH 问题) - I can't deploy app on remote server by `docker compose` from local machine (problem with SSH) Docker Swarm 可以在一台机器上运行吗? - Can Docker Swarm be ran on a single machine? Docker AWS 上的 Swarm:公开服务端口在 AWS 虚拟机上不起作用 - Docker Swarm on AWS: Expose service port not working on AWS virtual machine 如何按顺序部署 docker 群用户 docker 服务堆栈 - How can I deploy docker swarm user docker stack with services by order 我可以通过通过镜像ID引用映像的docker-compose.yml文件将服务部署到docker群吗? - Can I deploy a service to a docker swarm via a docker-compose.yml file that references the image by its ID?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM