[英]How to push docker images into a registry and pull them by docker-compose.yml file only
我是 docker 的新手,我在将图像推送到私有注册表并通过我们办公室另一台计算机中的 docker-compose.yml 文件拉取图像的过程中遇到了一些问题。
我的项目中有 2 个文件夹:nginx 和客户端。
nginx 是服务器,客户端是 create-react-app。
nginx文件夹:
默认.conf:
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";
}
}
server {
listen 3000;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}
客户端文件夹:
nginx/default.conf:
server { listen 3000; location / { root /usr/share/nginx/html; index index.html index.htm; } }
Dockerfile:
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
在 2 个文件夹之外,我有 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 和客户端)推送到注册表:
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
然后,我更新了我的 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:\\Or\\Web\\StreamImages\\TestDeploy\\nginx 要么不存在,要么不可访问,要么不是有效的 URL。”
我究竟做错了什么?
我需要帮助。
您需要删除部署环境中的build:
块,否则 Docker Compose 将尝试构建映像而不是拉取它们。 您还需要删除volumes:
否则它会期望在本地而不是在图像中找到源代码。
(我个人的建议是删除这些volumes:
无处不在,在 Docker 之外进行开发,并使您的 Docker 设置准确反映您的部署环境,但我似乎在这方面属于少数。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.