Django-CMS是一款基于Django框架的开源企业内容管理系统,它功能实用、安全可靠,支持拖拽上传图片、轮播图、Docker 部署等功能,可轻松进行二次开发,多用于构建企业官网。
本次实践为个人测试环境,操作系统版本为centos7.6。
hostname | IP地址 | 操作系统版本 | Docker版本 |
---|---|---|---|
jeven | 192.168.3.166 | centos 7.6 | 20.10.17 |
1.本次实践部署环境为个人测试环境,生产环境请谨慎使用;
2.在Docker环境下成功部署Django-CMS企业内容管理系统。
检查Docker服务是否正常运行,确保Docker正常运行。
[root@jeven ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2023-06-10 00:48:40 CST; 16h ago
Docs: https://docs.docker.com
Main PID: 9546 (dockerd)
Tasks: 15
Memory: 160.7M
检查Docker版本
[root@jeven ~]# docker -v
Docker version 20.10.17, build 100c701
检查Docker compose版本,确保2.0以上版本。
[root@jeven ~]# docker compose version
Docker Compose version v2.6.0
此版本使用运行的Python 3.9以及Django 3.2和Django CMS 3.11的最新版本。
[root@jeven data]# git clone https://github.com/django-cms/django-cms-quickstart.git
Cloning into 'django-cms-quickstart'...
remote: Enumerating objects: 301, done.
remote: Counting objects: 100% (118/118), done.
remote: Compressing objects: 100% (62/62), done.
remote: Total 301 (delta 91), reused 56 (delta 56), pack-reused 183
Receiving objects: 100% (301/301), 88.28 KiB | 0 bytes/s, done.
Resolving deltas: 100% (171/171), done.
[root@jeven data]# cd django-cms-quickstart/
[root@jeven django-cms-quickstart]# tree -L 2 ./
./
├── backend
│ ├── asgi.py
│ ├── __init__.py
│ ├── settings.py
│ ├── static
│ ├── templates
│ ├── urls.py
│ └── wsgi.py
├── docker-compose.yml
├── Dockerfile
├── LICENSE
├── manage.py
├── README.md
├── requirements.in
└── requirements.txt
3 directories, 12 files
查看Dockerfile文件内容
[root@jeven django-cms-quickstart]# cat Dockerfile
FROM python:3.9
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
RUN python manage.py collectstatic --noinput
CMD uwsgi --http=0.0.0.0:80 --module=backend.wsgi
查看docker-compose.yml文件内容
[root@jeven django-cms-quickstart]# cat docker-compose.yml
version: "3"
services:
web:
# the application's web service (container) will use an image based on our Dockerfile
build: .
# map the internal port 80 to port 8000 on the host
ports:
- "8000:80"
# map the host directory to app (which allows us to see and edit files inside the container)
volumes:
- ".:/app:rw"
- "./data:/data:rw"
# the default command to run whenever the container is launched
command: python manage.py runserver 0.0.0.0:80
# the URL 'postgres' or 'mysql' will point to the application's db service
networks:
- djangocmsnet
env_file: .env-local
database_default:
# Select one of the following db configurations for the database
image: postgres:13.5-alpine
ports:
- "5432:5432/tcp" # allow your local dev env to connect to the db
environment:
POSTGRES_DB: "db"
POSTGRES_PASSWORD: "password"
POSTGRES_HOST_AUTH_METHOD: "trust"
SERVICE_MANAGER: "fsm-postgres"
networks:
- djangocmsnet
volumes:
- ".:/app:rw"
networks:
djangocmsnet:
构建镜像django-cms-quickstart_web
docker compose build web
查询本地镜像
[root@jeven django-cms-quickstart]# docker images |grep web
django-cms-quickstart_web latest c2c85dab6120 29 minutes ago 1.15GB
lihaixin/webssh2 ssh 2e477b65711b 2 years ago 15.8MB
启动database_default容器
docker compose up -d database_default
[root@jeven django-cms-quickstart]# docker compose up -d database_default
[+] Running 9/9
⠿ database_default Pulled 24.9s
⠿ 59bf1c3509f3 Already exists 0.0s
⠿ c50e01d57241 Pull complete 0.7s
⠿ a0646b0f1ead Pull complete 0.8s
⠿ 08018e47fc43 Pull complete 8.2s
⠿ 6014f2775635 Pull complete 8.3s
⠿ 85760f97d4b8 Pull complete 8.4s
⠿ 3e07f59f91db Pull complete 8.4s
⠿ 3f86c399b0a1 Pull complete 8.5s
[+] Running 2/2
⠿ Network django-cms-quickstart_djangocmsnet Created 0.1s
⠿ Container django-cms-quickstart-database_default-1 Started 0.5s
数据库迁移
docker compose run web python manage.py migrate
创建Django-CMS的管理用户和密码。
docker compose run web python manage.py createsuperuser
使用docker compose快速一键部署Django-CMS
[root@jeven django-cms-quickstart]# docker compose up -d
[+] Running 2/2
⠿ Container django-cms-quickstart-web-1 Started 0.8s
⠿ Container django-cms-quickstart-database_default-1 Started 0.7s
检查Django-CMS容器状态
[root@jeven django-cms-quickstart]# docker compose ps
NAME COMMAND SERVICE STATUS PORTS
django-cms-quickstart-database_default-1 "docker-entrypoint.s…" database_default running 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp
django-cms-quickstart-web-1 "python manage.py ru…" web running 0.0.0.0:8000->80/tcp, :::8000->80/tcp
访问地址:http://192.168.3.166:8000/admin
账号密码:root/admin,为之前设置好的管理员账号和密码。
访问地址:http://192.168.3.166:8000/