代码之家  ›  专栏  ›  技术社区  ›  Or Assayag

如何将Docker映像推入注册表并仅通过docker-compose.yml文件将其拉入

  •  0
  • Or Assayag  · 技术社区  · 7 年前

    我是Docker的新成员,我对将图像推入私有注册表并通过Docker-compose.yml文件将其拉入我们办公室的其他计算机的过程有一些问题。

    我的项目中有两个文件夹:nginx和client。
    nginx是服务器,客户端是create react app。

    NGNX文件夹:

    默认:

    upstream client {
      server client:3000;
    }
    
    server {
      listen 80;
    
      location / {
        proxy_pass http://client;
      }
    
      location /sockjs-node {
        proxy_pass http://client;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
      }
    }
    


    Dockerfile:

    FROM nginx
    COPY ./default.conf /etc/nginx/conf.d/default.confd
    


    客户端文件夹:

    nginx/default.conf:

    server {
      listen 3000;
    
      location / {
        root /usr/share/nginx/html;
        index index.html index.htm;
      }
    }
    


    Dockerfile:

    FROM node:alpine as builder
    
    ARG REACT_APP_NODE_ENV
    ENV REACT_APP_NODE_ENV $REACT_APP_NODE_ENV
    
    WORKDIR /app
    COPY ./package.json ./
    RUN npm i
    COPY . .
    RUN npm run build
    
    FROM nginx
    EXPOSE 3000
    COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
    COPY --from=builder /app/build /usr/share/nginx/html
    



    在这两个文件夹之外,我还有docker-compose.yml文件:

    version: '3'
    services:
      nginx:
        restart: always
        build:
          dockerfile: Dockerfile
          context: ./nginx
        ports:
          - '3050:80'
      client:
        build:
          context: ./client
          dockerfile: Dockerfile
          args:
            - REACT_APP_NODE_ENV=production
        volumes:
          - /app/node_modules
          - ./client:/app
    



    当我在项目文件夹“docker compose up--build”中做的时候,一切都按我的期望工作。

    现在,我想把图像推到办公室的其他电脑里。
    我首先通过终端上的以下命令将2个映像(nginx和客户机)推送到注册表:

    docker build -t orassayag/osr_streamer_nginx:v1.0 .
    
    docker tag orassayag/osr_streamer_nginx:v1.0 <office_ip_address>:5000/orassayag/osr_streamer_nginx:v1.0
    
    docker push <office_ip_address>:5000/orassayag/osr_streamer_nginx:v1.0
    
    docker build -t orassayag/osr_streamer_client:v1.0 .
    
    docker tag orassayag/osr_streamer_client:v1.0 <office_ip_address>:5000/orassayag/osr_streamer_client:v1.0
    
    docker push <office_ip_address>:5000/orassayag/osr_streamer_client:v1.0
    



    然后,我更新docker-compose.yml文件如下:

    version: '3'
    services:
      nginx:
        image: <office_ip_address>:5000/orassayag/osr_streamer_nginx
        restart: always
        build:
          context: ./nginx
          dockerfile: Dockerfile
        ports:
          - '3050:80'
      client:
        image: <office_ip_address>:5000/orassayag/osr_streamer_client
        build:
          context: ./client
          dockerfile: Dockerfile
          args:
            - REACT_APP_NODE_ENV=production
        volumes:
          - /app/node_modules
          - ./client:/app
    



    我转到另一台计算机,创建了一个文件夹名“testdeploy”,在终端上运行“docker compose build--pull”,得到以下错误:

    错误:生成路径c:\或\web\streamimages\testdeploy\nginx不存在、不可访问或不是有效的URL。

    我做错什么了?
    我需要帮助。

    1 回复  |  直到 7 年前
        1
  •  1
  •   David Maze    7 年前

    你需要移除 build: 块在部署环境中,否则Docker Compose将尝试构建图像,而不是拉它们。您还需要删除 volumes: 否则,它将希望在本地而不是图像中找到源代码。

    (我个人的建议是去掉那些 卷: 到处 ,在Docker之外进行开发,让Docker的设置准确地反映您的部署环境,但我在这方面似乎占少数。)

    推荐文章