使用docker-compose部署服务

举报
winnerwhy 发表于 2024/09/26 08:41:57 2024/09/26
【摘要】 [root@master ~]# tar -zxvf Pig.tar.gz[root@master ~]# docker load -i Pig/CentOS_7.9.2009.tar[root@master ~]# cd Pig/[root@master Pig]# cat mysql_init.sh #!/bin/bashmysql_install_db --user=rootmysql...

[root@master ~]# tar -zxvf Pig.tar.gz

[root@master ~]# docker load -i Pig/CentOS_7.9.2009.tar

[root@master ~]# cd Pig/

[root@master Pig]# cat mysql_init.sh

#!/bin/bash
mysql_install_db --user=root
mysqld_safe --user=root &
sleep 8
mysqladmin -u root password 'root'
mysql -uroot -proot -e "grant all on *.* to 'root'@'%' identified by 'root'; flush privileges;"
mysql -uroot -proot < /opt/pig.sql
mysql -uroot -proot < /opt/pig_codegen.sql
mysql -uroot -proot < /opt/pig_config.sql
mysql -uroot -proot < /opt/pig_job.sql

[root@master Pig]# cat local.repo

[local]
name=local
baseurl=file:///opt/yum
gpgcheck=0
enabled=1

[root@master Pig]# cat Dockerfile-mariadb

FROM centos:centos7.9.2009
MAINTAINER Chinaskills
RUN rm -rf /etc/yum.repos.d/*
COPY local.repo /etc/yum.repos.d/
COPY yum /opt/yum
ENV LC_ALL en_US.UTF-8
RUN yum -y install mariadb-server mariadb
COPY mysql/* /opt/
COPY mysql_init.sh /opt/
RUN bash /opt/mysql_init.sh
EXPOSE 3306
CMD ["mysqld_safe","--user=root"]

[root@master Pig]# docker build -t pig-mariadb:v1.0 -f Dockerfile-mariadb .

[root@master Pig]# cat Dockerfile-redis

FROM centos:centos7.9.2009
MAINTAINER Chinaskills
RUN rm -rf /etc/yum.repos.d/*
COPY local.repo /etc/yum.repos.d/
COPY yum /opt/yum
RUN yum -y install redis
RUN sed -i 's/bind 127.0.0.1/bind 0.0.0.0/g' /etc/redis.conf && \
    sed -i 's/protected-mode yes/protected-mode no/g' /etc/redis.conf
EXPOSE 6379
CMD ["/usr/bin/redis-server","/etc/redis.conf"]

[root@master Pig]# docker build -t pig-redis:v1.0 -f Dockerfile-redis .


[root@master Pig]# cat pig_init.sh

#!/bin/bash
cd /root/
sleep 10
nohup java -jar pig-register.jar  &
sleep 10
nohup java -jar pig-gateway.jar  &
sleep 20
nohup java -jar pig-auth.jar  &
sleep 10
nohup java -jar pig-upms-biz.jar

[root@master Pig]# cat Dockerfile-pig

FROM centos:centos7.9.2009
MAINTAINER Chinaskills
COPY service /root
ADD yum /opt/yum
RUN rm -rfv /etc/yum.repos.d/*
COPY local.repo /etc/yum.repos.d/local.repo
RUN yum install -y java-1.8.0*
COPY pig_init.sh /root
RUN chmod +x /root/pig_init.sh
EXPOSE 8848 9999 3000 4000
CMD ["/bin/bash","/root/pig_init.sh"]

[root@k8s-worker-node1 Pig]# docker build -t pig-service:v1.0 -f Dockerfile-pig .

[root@master Pig]# cat Dockerfile-nginx

FROM centos:centos7.9.2009
MAINTAINER Chinaskills
RUN rm -rf /etc/yum.repos.d/*
COPY local.repo /etc/yum.repos.d/
COPY yum /opt/yum
RUN yum -y install nginx
COPY nginx/dist /data
ADD nginx/pig-ui.conf /etc/nginx/conf.d/
EXPOSE 80
CMD ["nginx","-g","daemon off;"]

[root@k8s-worker-node1 Pig]# docker build -t pig-ui:v1.0 -f Dockerfile-nginx .

[root@master Pig]# cat docker-compose.yaml

version: '3'
services:
  pig-mysql:
    image: pig-mariadb:v1.0
    container_name: pig-mariadb
    environment:
      MYSQL_ROOT_PASSWORD: root
    ports:
      - "3306:3306"
    restart: always
    links:
      - pig-service:pig-register

  pig-redis:
    image: pig-redis:v1.0
    container_name: pig-redis
    ports:
      - 6379:6379
    restart: always
    links:
      - pig-service:pig-register

  pig-service:
    image: pig-service:v1.0
    container_name: pig-service
    hostname: pig-service
    ports:
      - "8848:8848"
      - "9999:9999"
    restart: always
    extra_hosts:
      - pig-register:127.0.0.1
      - pig-upms:127.0.0.1
      - pig-gateway:127.0.0.1
      - pig-auth:127.0.0.1
      - pig-hou:127.0.0.1
    stdin_open: true
    tty: true
    privileged: true

  pig-ui:
    image: pig-ui:v1.0
    container_name: pig-ui
    ports:
      - 8888:80
    restart: always
    links:
      - pig-service:pig-gateway

[root@k8s-worker-node1 Pig]# docker-compose up -d

[root@k8s-worker-node1 Pig]# docker-compose ps


【版权声明】本文为华为云社区用户原创内容,未经允许不得转载,如需转载请自行联系原作者进行授权。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。