docker构建laravel8 + GO项目镜像,集群发布

laravel项目

Dockerfile和laravel.conf都在/var/www/laravel下

Dockerfile

FROM centos:8.4.2105

ARG namepath=/var/www/laravel

COPY . ${namepath}

WORKDIR ${namepath}

RUN rename '.repo' '.repo.bak' /etc/yum.repos.d/*.repo \
    && curl -o /etc/yum.repos.d/Centos-vault-8.5.2111.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo \
    && curl -o /etc/yum.repos.d/epel-archive-8.repo https://mirrors.aliyun.com/repo/epel-archive-8.repo \
    && sed -i 's/mirrors.cloud.aliyuncs.com/url_tmp/g'  /etc/yum.repos.d/Centos-vault-8.5.2111.repo \
    && sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo \
    && sed -i 's/url_tmp/mirrors.aliyun.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo \
    && sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/epel-archive-8.repo \
    && dnf -y clean all \
    && dnf -y makecache


RUN dnf -y install epel-release \
    && dnf -y update epel-release \
    && dnf -y clean all \
    && dnf -y makecache \
    && dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm \
    && dnf -y module enable php:remi-8.0\
    && dnf -y install php php-curl php-dom php-exif php-fileinfo php-fpm php-gd php-hash php-json php-mbstring php-mysqli php-openssl php-pcre php-xml libsodium \
    && mkdir -p /run/php-fpm \
    && dnf -y install http://nginx.org/packages/centos/8/x86_64/RPMS/nginx-1.16.1-1.el8.ngx.x86_64.rpm \
    && mv laravel.conf /etc/nginx/conf.d/default.conf \
    && dnf -y install composer \
    && composer install --no-interaction --no-plugins --no-scripts --prefer-dist --ignore-platform-req=ext-bcmath \
    && chmod -R 777 storage \
    && chmod -R 777 bootstrap




CMD php-fpm && /usr/sbin/nginx -g 'daemon off;'

EXPOSE 8080

laravel.conf

server {
    listen 8080;
    server_name  localhost;
    root /var/www/laravel/public;
    index index.html index.htm index.php;

    charset utf-8;

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

    location / {
        try_files $uri $uri/ /index.php?$query_string;
        if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.php?s=$1  last;
            break;
        }
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

docker构建镜像以及运行容器项目

1.构建镜像

#构建镜像
docker build -t xts_api_images/api.xxxx.com:0.2 .

2.上到阿里云容器镜像服务

#登录阿里云Docker Registry 
docker login --username=v-2212582xxx449-6 registry.cn-zhangjiakou.aliyuncs.com
#标记镜像
docker tag 79d250cc2248 registry.cn-zhangjiakou.aliyuncs.com/xts_api_images/api.xxx.com:0.2
#将镜像推送到Registry
docker push registry.cn-zhangjiakou.aliyuncs.com/xts_api_images/api.xxx.com:0.2

3.运行容器项目

[root@iZvixj0oze6411Z ~]# docker images
REPOSITORY                                                               TAG                 IMAGE ID            CREATED             SIZE
registry.cn-zhangjiakou.aliyuncs.com/xts_api_images/api.xxx.com   0.2                 79d250cc2248        33 minutes ago      566 MB
xts_api_images/api.xxx.com                                        0.2                 79d250cc2248        33 minutes ago      566 MB
docker.io/centos                                                         8.4.2105            5d0da3dc9764        6 months ago        231 MB
[root@iZvixj0oze6411Z ~]# docker run -d -it --name xtsv0.2 -p 8080:8080 xts_api_images/api.xxx.com:0.2
963493b48e7be36e1f9c3d050645ac5a6045194cb0acc338732f54b89ed0176a
[root@iZvixj0oze6411Z ~]# docker exec -it 963493b48e7be36e1f9c3d050645ac5a6045194cb0acc338732f54b89ed0176a /bin/bash
[root@963493b48e7b laravel]# curl localhost:8080

GO Dockerfile

FROM golang:1.17

ARG namepath=/var/www/project

COPY . ${namepath}

WORKDIR ${namepath}

ENV GO111MODULE=on \
    GOPROXY=https://goproxy.cn,direct \
    ENV=prod

RUN go build -o webserver

EXPOSE 8087

ENTRYPOINT ["./webserver"]
本作品采用《CC 协议》,转载必须注明作者和本文链接
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!