将具有多个容器的docker-compose项目部署到Google Cloud

时间:2019-03-08 17:13:23

标签: wordpress nginx docker-compose mariadb google-kubernetes-engine

我想将我的本地docker项目部署到google kubernetes引擎(或者如果它对google vm引擎更好-我不知道哪个更适合此项目)。在kubernetes引擎上部署并在端口80上暴露了pod之后。未显示任何wordpress站点。

现在我不知道是否是因为我对cloudbuild.yaml的错误理解?我可以为我的Pod建立多个容器吗?如果可以,例如,如何连接到wordpress或mysql容器?

我正在使用Google Cloud Builder从我的存储库(使用cloudbuilder.yaml)而非Dockerfile构建映像。

我的docker项目由使用以下服务的docker-compose.yaml组成:

  1. mariadb:latest
  2. nginx(使用自己的Dockerfile进行自定义构建)
  3. wordpress(使用wordpress cli自定义构建,拥有Dockerfile)

我的docker-compose.yaml(view formatted version here

version: '3'

services:
  db:
    image: mariadb:latest
    container_name: mysql
    volumes:
      - mariadbdata:/var/lib/mysql
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=the_root_pass
      - MYSQL_DATABASE=wordpress
      - MYSQL_USER=wordpress
      - MYSQL_PASSWORD=eveneasier

   my-wordpress:
    container_name: wordpress
    depends_on:
      - db
    build:
      context: .
      dockerfile: build/wordpress/Dockerfile
    restart: always
    volumes:
      - ./wordpress:/var/www/html
    environment:
      - WORDPRESS_DB_HOST=db:3306
      - WORDPRESS_DB_USER=wordpress
      - WORDPRESS_DB_PASSWORD=eveneasier
      - WORDPRESS_DB_NAME=wordpress

  my-nginx:
    container_name: nginx
    depends_on:
      - my-wordpress
    restart: always
    volumes:
      - ./nginx:/etc/nginx/conf.d
      - ./logs/nginx
      - ./wordpress:/var/www/html
    build:
      context: .
      dockerfile: build/nginx/Dockerfile
    ports:
      - "8022:80"
      - "44322:443"
volumes:
  mariadbdata:
    driver: local

这是我的cloudbuild.yaml

steps:
      - name: 'docker/compose:1.19.0'
        args: ['up', '-d']

      - name: 'gcr.io/cloud-builders/docker'
        args: ['tag', 'mariadb', 'gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA']

      - name: 'gcr.io/cloud-builders/docker'
        args: ['tag', 'workspace_my-nginx', 'gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA']

      - name: 'gcr.io/cloud-builders/docker'
        args: ['tag', 'workspace_my-wordpress', 'gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA']

    images: ['gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA']

在撰写本文时,我想知道我的nginx.conf是否是问题所在,因为它使用localhost(127.0.0.1)作为主机。如果是这样,我的其他问题仍然存在。

我的nginx.conf:

        server {
        listen 80;
        server_name 127.0.0.1;

        root /var/www/html;
        index index.php;

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        location / {
            try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass wordpress:9000;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
        }
    }

0 个答案:

没有答案