我用这种方式定义了一个简单的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

issue我的问题是当我执行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
提前致谢! :)

最佳答案

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来完成相同的操作。

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

关于docker - 错误无法将图像 'library/web:latest'推送到注册表 'docker.io'。错误:被拒绝:请求的对资源的访问被拒绝-Kompose,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/62226760/

10-13 06:42