apache2: 权限被拒绝: AH00072: make_sock: 无法绑定到地址 0.0.0.0:80 没有可用的侦听套接字,正在关闭

Jim*_*m C 5 apache2 openshift docker kubernetes docker-compose

我正在尝试一个非常简单的教程,解释如何将 docker-compose 转换为 minishift (Minishift 和 Kompose。我尝试转换并推送 docker-compose.yml 示例

\n\n
version: "2"\n\nservices:\n\n  redis-master:\n    image: k8s.gcr.io/redis:e2e \n    ports:\n      - "6379"\n\n  redis-slave:\n    image: gcr.io/google_samples/gb-redisslave:v1\n    ports:\n      - "6379"\n    environment:\n      - GET_HOSTS_FROM=dns\n\n  frontend:\n    image: gcr.io/google-samples/gb-frontend:v4\n    ports:\n      - "80:80"\n    environment:\n      - GET_HOSTS_FROM=dns\n    labels:\n      kompose.service.type: LoadBalancer\n
Run Code Online (Sandbox Code Playgroud)\n\n

从这些日志中可以看到,我成功地编写并推送了:

\n\n
C:\\Users\\Cast\\docker-compose-to-minishift>kompose-windows-amd64 up --provider=openshift\n[36mINFO[0m We are going to create OpenShift DeploymentConfigs, Services and PersistentVolumeClaims for your Dockerized application.\nIf you need different kind of resources, use the \'kompose convert\' and \'oc create -f\' commands instead.\n\n[36mINFO[0m Deploying application in "myproject" namespace\n[36mINFO[0m Successfully created Service: frontend\n[36mINFO[0m Successfully created Service: redis-master\n[36mINFO[0m Successfully created Service: redis-slave\n[36mINFO[0m Successfully created DeploymentConfig: frontend\n[36mINFO[0m Successfully created ImageStream: frontend\n[36mINFO[0m Successfully created DeploymentConfig: redis-master\n[36mINFO[0m Successfully created ImageStream: redis-master\n[36mINFO[0m Successfully created DeploymentConfig: redis-slave\n[36mINFO[0m Successfully created ImageStream: redis-slave\n\nYour application has been deployed to OpenShift. You can run \'oc get dc,svc,is,pvc\' for details.\n\nC:\\Users\\Cast\\docker-compose-to-minishift>oc get dc\nNAME           REVISION   DESIRED   CURRENT   TRIGGERED BY\nfrontend       0          1         0         config,image(frontend:v4)\nredis-master   1          1         1         config,image(redis-master:e2e)\nredis-slave    1          1         1         config,image(redis-slave:v1)\n
Run Code Online (Sandbox Code Playgroud)\n\n

尽管如此,我无法访问 Web 应用程序并查看日志,我发现“容器前端经常崩溃。它必须等待才能再次重新启动”,然后单击详细信息:

\n\n
AH00558: apache2: Could not reliably determine the server\'s fully qualified domain name, using 172.17.0.13. Set the \'ServerName\' directive globally to suppress this message\n(13)Permission denied: AH00072: make_sock: could not bind to address [::]:80\n(13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:80\nno listening sockets available, shutting down\nAH00015: Unable to open logs\n
Run Code Online (Sandbox Code Playgroud)\n\n

搜索周围我发现有人建议从端口 80 更改为一些非 root 特权端口(例如 8080)。因此,我在 docker-compose 中更改了它,手动删除了命名空间 myproject,在 OpenShift Web Console 中重新创建了它,然后尝试再次运行。具有相同消息的完全相同的异常。

\n\n

如果相关的话,我有另一个 cmd 窗口

\n\n
C:\\Users\\Cast\\docker-compose-to-minishift>kubectl proxy --port=8080\nStarting to serve on 127.0.0.1:8080\n
Run Code Online (Sandbox Code Playgroud)\n\n

我对从 docker-compose 转向 minishift 还很陌生(说实话,我是第一次使用 Kompose 工具)。

\n\n

我的主要问题:如果我已经在 docker-compose 中将端口从 80:80 更改为 8080:8080,为什么我仍然遇到同样的问题

\n\n
  frontend:\n    image: gcr.io/google-samples/gb-frontend:v4\n    ports:\n      - "8080:8080"\n
Run Code Online (Sandbox Code Playgroud)\n\n

第二个问题:我必须检查什么才能了解​​为什么我无法启动前端服务?所提供的例外是相当有限的。

\n\n

*** 已编辑

\n\n

由 kompose 转换的 docker-compose (仅前端文件)

\n\n

前端图像流

\n\n
apiVersion: v1\nkind: ImageStream\nmetadata:\n  creationTimestamp: null\n  labels:\n    io.kompose.service: frontend\n  name: frontend\nspec:\n  tags:\n  - annotations: null\n    from:\n      kind: DockerImage\n      name: gcr.io/google-samples/gb-frontend:v4\n    generation: null\n    importPolicy: {}\n    name: v4\nstatus:\n  dockerImageRepository: ""\n
Run Code Online (Sandbox Code Playgroud)\n\n

前端服务

\n\n
apiVersion: v1\nkind: Service\nmetadata:\n  annotations:\n    kompose.cmd: C:\\tools\\kompose-windows-amd64.exe convert --provider=openshift\n    kompose.service.type: LoadBalancer\n    kompose.version: 1.19.0 (f63a961c)\n  creationTimestamp: null\n  labels:\n    io.kompose.service: frontend\n  name: frontend\nspec:\n  ports:\n  - name: "8080"\n    port: 8080\n    targetPort: 8080\n  selector:\n    io.kompose.service: frontend\n  type: LoadBalancer\nstatus:\n  loadBalancer: {}\n
Run Code Online (Sandbox Code Playgroud)\n\n

前端部署配置

\n\n
apiVersion: v1\nkind: DeploymentConfig\nmetadata:\n  annotations:\n    kompose.cmd: C:\\tools\\kompose-windows-amd64.exe convert --provider=openshift\n    kompose.service.type: LoadBalancer\n    kompose.version: 1.19.0 (f63a961c)\n  creationTimestamp: null\n  labels:\n    io.kompose.service: frontend\n  name: frontend\nspec:\n  replicas: 1\n  selector:\n    io.kompose.service: frontend\n  strategy:\n    resources: {}\n  template:\n    metadata:\n      creationTimestamp: null\n      labels:\n        io.kompose.service: frontend\n    spec:\n      containers:\n      - env:\n        - name: GET_HOSTS_FROM\n          value: dns\n        image: \' \'\n        name: frontend\n        ports:\n        - containerPort: 8080\n        resources: {}\n      restartPolicy: Always\n  test: false\n  triggers:\n  - type: ConfigChange\n  - imageChangeParams:\n      automatic: true\n      containerNames:\n      - frontend\n      from:\n        kind: ImageStreamTag\n        name: frontend:v4\n    type: ImageChange\nstatus: {}\n
Run Code Online (Sandbox Code Playgroud)\n\n

添加了所有日志(我删除了 Redis,只留下了前端服务,因为它是唯一导致问题的原因):

\n\n
Windows PowerShell\nCopyright (C) Microsoft Corporation. Todos os direitos reservados.\n\nExperimente a nova plataforma cruzada PowerShell https://aka.ms/pscore6\n\nPS C:\\Windows\\system32> cd C:\\to_learn\\docker-compose-to-minishift\\first-try\nPS C:\\to_learn\\docker-compose-to-minishift\\first-try> kompose-windows-amd64 up --provider=openshift\n[36mINFO[0m We are going to create OpenShift DeploymentConfigs, Services and PersistentVolumeClaims for your Dockerized application.\nIf you need different kind of resources, use the \'kompose convert\' and \'oc create -f\' commands instead.\n\n[36mINFO[0m Deploying application in "myproject" namespace\n[36mINFO[0m Successfully created Service: frontend\n[36mINFO[0m Successfully created DeploymentConfig: frontend\n[36mINFO[0m Successfully created ImageStream: frontend\n\nYour application has been deployed to OpenShift. You can run \'oc get dc,svc,is,pvc\' for details.\nPS C:\\to_learn\\docker-compose-to-minishift\\first-try> oc expose service/frontend\nroute.route.openshift.io/frontend exposed\nPS C:\\to_learn\\docker-compose-to-minishift\\first-try> minishift openshift service frontend --namespace=myproject\n|-----------|----------|----------------------|-------------------------------------------------|--------|\n| NAMESPACE |   NAME   |       NODEPORT       |                    ROUTE-URL                    | WEIGHT |\n|-----------|----------|----------------------|-------------------------------------------------|--------|\n| myproject | frontend | 192.168.99.101:30215 | http://frontend-myproject.192.168.99.101.nip.io |        |\n|-----------|----------|----------------------|-------------------------------------------------|--------|\nPS C:\\to_learn\\docker-compose-to-minishift\\first-try>\n
Run Code Online (Sandbox Code Playgroud)\n\n

当我尝试在 Chrome 中打开http://frontend-myproject.192.168.99.101.nip.io时:

\n\n
Application is not available\nThe application is currently not serving requests at this endpoint. It may not have been started or is still starting.\n...\n
Run Code Online (Sandbox Code Playgroud)\n\n

已编辑(尝试部署另一个示例应用程序)

\n\n
PS C:\\to_learn\\docker-compose-to-minishift\\first-try>  nslookup x.127.0.0.1.xip.io\nServidor:  one.one.one.one\nAddress:  1.1.1.1\n\nN\xc3\xa3o \xc3\xa9 resposta autoritativa:\nNome:    x.127.0.0.1.xip.io\nAddress:  127.0.0.1\n\nPS C:\\to_learn\\docker-compose-to-minishift\\first-try> oc version\noc v3.11.0+0cbc58b\nkubernetes v1.11.0+d4cacc0\nfeatures: Basic-Auth SSPI Kerberos SPNEGO\n\nServer https://192.168.99.101:8443\nkubernetes v1.11.0+d4cacc0\nPS C:\\to_learn\\docker-compose-to-minishift\\first-try>  oc new-app --name=\'cotd\' --labels name=\'cotd\' php~https://github.com/devopswith-openshift/cotd.git -e SELECTOR=cats\n--> Found image dc5aa55 (2 months old) in image stream "openshift/php" under tag "7.1" for "php"\n\n    Apache 2.4 with PHP 7.1\n    -----------------------\n    PHP 7.1 available as container is a base platform for building and running various PHP 7.1 applications and frameworks. PHP is an HTML-embedded scripting language. PHP attempts to make it easy for developers to write dynamically generated web pages. PHP also offers built-in database integration for several commercial and non-commercial database management systems, so writing a database-enabled webpage with PHP is fairly simple. The most common use of PHP coding is probably as a replacement for CGI scripts.\n\n    Tags: builder, php, php71, rh-php71\n\n    * A source build using source code from https://github.com/devopswith-openshift/cotd.git will be created\n      * The resulting image will be pushed to image stream tag "cotd:latest"\n      * Use \'start-build\' to trigger a new build\n    * This image will be deployed in deployment config "cotd"\n    * Ports 8080/tcp, 8443/tcp will be load balanced by service "cotd"\n      * Other containers can access this service through the hostname "cotd"\n\n--> Creating resources with label name=cotd ...\n    imagestream.image.openshift.io "cotd" created\n    buildconfig.build.openshift.io "cotd" created\n    deploymentconfig.apps.openshift.io "cotd" created\n    service "cotd" created\n--> Success\n    Build scheduled, use \'oc logs -f bc/cotd\' to track its progress.\n    Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:\n     \'oc expose svc/cotd\'\n    Run \'oc status\' to view your app.\nPS C:\\to_learn\\docker-compose-to-minishift\\first-try> oc expose svc/cotd\nroute.route.openshift.io/cotd exposed\nPS C:\\to_learn\\docker-compose-to-minishift\\first-try> oc status\nIn project myproject on server https://192.168.99.101:8443\n\nhttp://cotd-myproject.192.168.99.101.nip.io to pod port 8080-tcp (svc/cotd)\n  dc/cotd deploys istag/cotd:latest <-\n    bc/cotd source builds https://github.com/devopswith-openshift/cotd.git on openshift/php:7.1\n      build #1 pending for 11 minutes\n    deployment #1 waiting on image or update\n\nhttp://frontend-myproject.192.168.99.101.nip.io to pod port 8080 (svc/frontend)\n  dc/frontend deploys istag/frontend:v4\n    deployment #1 waiting on image or update\n\n\n4 infos identified, use \'oc status --suggest\' to see details.\nPS C:\\to_learn\\docker-compose-to-minishift\\first-try> oc status --suggest\nIn project myproject on server https://192.168.99.101:8443\n\nhttp://cotd-myproject.192.168.99.101.nip.io to pod port 8080-tcp (svc/cotd)\n  dc/cotd deploys istag/cotd:latest <-\n    bc/cotd source builds https://github.com/devopswith-openshift/cotd.git on openshift/php:7.1\n      build #1 pending for 12 minutes\n    deployment #1 waiting on image or update\n\nhttp://frontend-myproject.192.168.99.101.nip.io to pod port 8080 (svc/frontend)\n  dc/frontend deploys istag/frontend:v4\n    deployment #1 waiting on image or update\n\nInfo:\n  * dc/cotd has no readiness probe to verify pods are ready to accept traffic or ensure deployment is successful.\n    try: oc set probe dc/cotd --readiness ...\n  * dc/cotd has no liveness probe to verify pods are still running.\n    try: oc set probe dc/cotd --liveness ...\n  * dc/frontend has no readiness probe to verify pods are ready to accept traffic or ensure deployment is successful.\n    try: oc set probe dc/frontend --readiness ...\n  * dc/frontend has no liveness probe to verify pods are still running.\n    try: oc set probe dc/frontend --liveness ...\n\nView details with \'oc describe <resource>/<name>\' or list everything with \'oc get all\'.\nPS C:\\to_learn\\docker-compose-to-minishift\\first-try>\n
Run Code Online (Sandbox Code Playgroud)\n\n

构建待定状态

\n\n

cotd-myproject

\n

Muk*_*han 7

当您使用像 bitnami 官方镜像这样的非根容器时,就会发生这种情况。

当需要与主机网络绑定时,我们使用user:rootnetwork_mode: host

  apache:
    image: bitnami/apache:2.4
    container_name: "apache"
    ports:
      - 80:80
    network_mode: host
    privileged: true
    user: root
    environment:
      DOCKER_HOST: "unix:///var/run/docker.sock"
    env_file:
      - .env
    volumes:
      - ./setup/apache/httpd.conf:/opt/bitnami/apache/conf/httpd.conf
Run Code Online (Sandbox Code Playgroud)