错误无法将映像“ library / web:latest”推送到注册表“ docker.io”。错误:被拒绝:请求的对资源的访问被拒绝-Kompose

时间:2020-06-06 02:58:49

标签: docker kubernetes docker-compose kompose

我有一个这样定义的简单docker-compose.yml文件:

version: '3'
services:
  db:
    image: postgres:10.5-alpine
    ports:
      - 5432:5432
    volumes:
      - ./tmp/postgres_data:/var/lib/postgresql/data
  web:
    build:
      context: .
      dockerfile: Dockerfile
    command: /bin/bash -c "rm -f /tmp/server.pid && bundle exec rails server -b 0.0.0.0 -P /tmp/server.pid"
    ports:
      - 3000:3000
    depends_on:
      - db
    volumes:
      - .:/app 

我正在使用[ Kompose ](https://kubernetes.io/docs/tasks/configure-pod-container/translate-compose-kubernetes/#kompose-up)将我的docker-compose.yml转换为Kubernetes

当我这样做时 kompose convert,一切看起来都很好。

这是输出:

 ✗ kompose convert  
    INFO Kubernetes file "db-service.yaml" created    
    INFO Kubernetes file "web-service.yaml" created   
    INFO Kubernetes file "db-deployment.yaml" created 
    INFO Kubernetes file "db-claim0-persistentvolumeclaim.yaml" created 
    INFO Kubernetes file "web-deployment.yaml" created 
    INFO Kubernetes file "web-claim0-persistentvolumeclaim.yaml" created 

??我的问题是我kompose up遇到以下错误??

✗ kompose up   
WARN Volume mount on the host "/Users/salo/Desktop/ibm-watson-ruby/tmp/postgres_data" isn't supported - ignoring path on the host 
INFO Build key detected. Attempting to build image 'web' 
INFO Building image 'web' from directory 'ibm-watson-ruby' 
INFO Image 'web' from directory 'ibm-watson-ruby' built successfully 
INFO Push image enabled. Attempting to push image 'web' 
INFO Pushing image 'library/web:latest' to registry 'docker.io' 
WARN Unable to retrieve .docker/config.json authentication details. Check that 'docker login' works successfully on the command line.: Failed to read authentication from dockercfg 
INFO Authentication credentials are not detected. Will try push without authentication. 
INFO Attempting authentication credentials 'docker.io 
ERRO Unable to push image 'library/web:latest' to registry 'docker.io'. Error: denied: requested access to the resource is denied 
FATA Error while deploying application: k.Transform failed: Unable to push Docker image for service web: unable to push docker image(s). Check that `docker login` works successfully on the command line 

请注意,我目前已登录Docker Hub帐户。我做了docker login

提前谢谢! :)

1 个答案:

答案 0 :(得分:0)

Kubernetes基本上需要Docker注册表才能工作;它无法生成本地图像。您提到您有一个Docker Hub帐户,因此需要在image:文件中将引用添加为容器的docker-compose.yml

version: '3'
services:
  web:
    build: .
    image: myname/web # <-- add this line
    ports:
      - 3000:3000
    depends_on:
      - db
    # command: is in the image
    # volumes: overwrite code in the image and don't work in k8s

当Kompose尝试推送图像时,它将使用image:名称。您应该可以单独尝试docker-compose push来完成相同的操作。

请注意,我删除了将应用程序代码绑定安装到容器中的volumes:。此设置在Kubernetes中不起作用:它无权访问本地系统,并且您无法预测哪个节点将实际运行您的应用程序。值得在普通Docker中仔细检查您构建的映像是否按预期方式工作,而不会覆盖其代码。 (在Docker中进行调试比在Kubernetes中进行调试更容易。)