侧边栏壁纸
  • 累计撰写 30 篇文章
  • 累计创建 3 个标签
  • 累计收到 4 条评论
标签搜索

目 录CONTENT

文章目录

广西区赛docekr-compose编排

小裴
2023-03-21 / 0 评论 / 0 点赞 / 94 阅读 / 715 字

容器部署基于Django博客系统
容器化部署Memcached

[root@k8s-master-node1 DjangoBlog]# vi Dockerfile-memcached 
FROM centos:centos7.9.2009
MAINTAINER xxx
RUN rm -rf /etc/yum.repos.d/*
COPY local.repo /etc/yum.repos.d/
COPY yum /root/yum
RUN yum install -y libevent libevent-devel
RUN yum install -y memcached
EXPOSE 11211
ENTRYPOINT /usr/bin/memcached -u root
[root@k8s-master-node1 DjangoBlog]# docker build -t blog-memcached:v1.0 -f Dockerfile-memcached .

容器化部署MariaDB

[root@k8s-master-node1 DjangoBlog]# vi 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 -e "create database djangoblog;use djangoblog;source /opt/sqlfile.sql;"
[root@k8s-master-node1 DjangoBlog]# vi Dockerfile-mariadb
FROM centos:centos7.9.2009
MAINTAINER CSQ
RUN rm -rf /etc/yum.repos.d/*
COPY local.repo /etc/yum.repos.d/
COPY yum /root/yum
ENV LC_ALL en_US.UTF-8
RUN yum install -y mariadb-server
COPY mysql_init.sh /opt/
COPY sqlfile.sql /opt
RUN bash /opt/mysql_init.sh
EXPOSE 3306
CMD ["mysqld_safe","--user=root"]

容器化部署前端服务

[root@k8s-master-node1 DjangoBlog]# vi Dockerfile-nginx 
FROM centos:centos7.9.2009
MAINTAINER CSQ
RUN rm -rf /etc/yum.repos.d/*
COPY local.repo /etc/yum.repos.d/
COPY yum /root/yum
RUN yum install -y nginx
ADD nginx.conf /etc/nginx/nginx.conf
RUN /bin/bash -c 'echo init ok'
EXPOSE 80
CMD ["nignx","-g","daemon off;"]

容器化部署博客系统

[root@k8s-master-node1 DjangoBlog]# vi Dockerfile-blog
FROM centos:centos7.9.2009
MAINTAINER CSQ
RUN rm -rf /etc/yum.repos.d/*
COPY local.repo /etc/yum.repos.d/
COPY yum /root/yum
RUN yum install -y make openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-devel python-devel mysql-devel
COPY Python-3.6.5.tgz /opt
RUN tar -zxvf /opt/Python-3.6.5.tgz
RUN mv   Python-3.6.5 /usr/local
RUN cd /usr/bin/Python-3.6.5/ && ./configure && make && make install
RUN ln -s /usr/local/python3/bin/python3 /usr/bin/python3
RUN ln -s /usr/local/python3/bin/pip3  /usr/bin/pip3
ADD requirements.txt requirements.txt
COPY Python-pip /opt
RUN pip3 install --upgrade pip --no-index --find-links=/opt
RUN pip3 install -r requirements.txt --no-index --find-links=/opt
RUN pip3 install  gunicorn[gevent] --no-index --find-links=/opt
RUN pip3 cache purge
RUN mkdir -p /code/djangoBlog
ADD . /code/djangoBlog
RUN chmod +x /code/djangoBlog/bin/docker_start.sh
ENTRYPOINT ["/code/djangoBlog/bin/docker_start.sh"]
[root@k8s-master-node1 DjangoBlog]# docker build -t blog-service:v1.0 -f Dockerfile-blog .

编排docker-compose.yaml

[root@k8s-master-node1 DjangoBlog]# vi docker-compose.yaml
version: '3'
services:
  memcached:
   restart: always
   image: blog-memcached:v1.0
   container_name: blog-memcached
   ports:
    - "11211:11211"
  db:
   restart: always
   image: blog-mysql:v1.0
   container_name: blog-mysql
   environment:
    - MYSQL_DATABASE=djangoblog
    - MYSQL_ROOT_PASSWORD=root
   ports:
    - 3306:3306
   depends_on:
    - memcached
  djangoblog:
   restart: always
   image: blog-service:v1.0
   container_name: blog-service:v1.0
   ports:
    - "8000:8000"
   environment:
    - DJANGO_MYSQL_DATABASE=djangoblog
    - DJANGO_MYSQL_USER=root
    - DJANGO_MYSQL_PASSWORD=root
    - DJANGO_MYSQL_HOST=db
    - DJANGO_MYSQL_PORT=3306
    - DJANGO_MEMCHACED_LOCATION=memcached:11211
   volumes:
    - ./collectedstatic:/code/djangoBlog/collectedstatic
   links:
    - db
    - memcached
   depends_on:
    - db
  nginx:
   restart: always
   image: blog-nginx:v1.0
   container_name: blog-nginx
   ports:
    - "8888:80"
    - "443:443"
   volumes:
    - ./collectedstatic:/code/djangoblog/collectedstatic
   links:
    - djangoblog:dangoblog

[root@k8s-master-node1 DjangoBlog]# docker-compose up -d
[+] Running 5/5
⠿ Network djangoblog_default Created 0.1s
⠿ Container blog-memcached Started 1.5s
⠿ Container blog-mysql Started 2.4s
⠿ Container blog-service Started 3.6s
⠿ Container blog-nginx Started 4.4s

0

评论区