案例一、
wordpress
创建网络
docker network create wordpress-network
创建容器
docker volume create --name mariadb_data
docker run -d --name mariadb --restart=always \
-p 3306:3306 \
--env MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=yes \
--env ALLOW_EMPTY_PASSWORD=yes \
--env MARIADB_USER=guest \
--env MARIADB_PASSWORD=bitnami \
--env MARIADB_DATABASE=bitnami_wordpress \
--network wordpress-network \
--volume mariadb_data:/bitnami/mariadb \
swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/mariadb:11.4.4
创建卷
docker volume create --name wordpress_data
创建wordpress
docker run -d --name wordpress --restart=always \
-p 8081:80 -p 8443:443 \
--env ALLOW_EMPTY_PASSWORD=yes \
--env WORDPRESS_DATABASE_USER=guest \
--env WORDPRESS_DATABASE_PASSWORD=bitnami \
--env WORDPRESS_DATABASE_NAME=bitnami_wordpress \
--network wordpress-network \
--volume wordpress_data:/bitnami/wordpress \
swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/wordpress:php7.4-apache
删除/var/www/html/wp-config.php或者改名 mv /var/www/html/wp-config.php /var/www/html/wp-config.php.bak
http://192.168.15.10:8081/wp-admin/setup-config.php
设置完毕即可访问。
案例二:
mkdir -p /app/data/mysql
启动
docker run -d --name mysql8.0 --restart=always \
-p 3306:3306 \
-v /app/data/mysql:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=root \
swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/mysql:8.0.39
案例三:
mkdir -p /app/tomcat/conf
mkdir -p /app/tomcat/webapps
mkdir -p /app/tomcat/logs
mkdir -p /app/tomcat/logsRoot
docker run -d --name tomcat --restart=always -p 8088:8080 swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/tomcat:8-jdk8-openjdk
docker exec -it tomcat /bin/bash
/usr/local/tomcat/webapps
docker cp tomcat:/usr/local/tomcat/conf /app/tomcat/
docker run -d --name tomcat -p 8088:8080 -v /app/tomcat/conf:/usr/local/tomcat/conf -v /app/tomcat/webapps:/usr/local/tomcat/webapps -v /app/tomcat/logs/:/usr/local/tomcat/logs -v /app/tomcat/logsRoot/:/usr/local/tomcat/logsRoot swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/tomcat:8-jdk8-openjdk
然后就可以在 /app/tomcat/webapps中上传文件,进行页面展示了。
案例四:
mkdir -p /app/nginx/conf
mkdir -p /app/nginx/logs
mkdir -p /app/nginx/html
docker run --name nginx -p 9001:80 -d harbor.dscloud.com:8443/library/nginx:1.23.1
docker cp nginx:/etc/nginx/nginx.conf /app/nginx/conf/nginx.conf
docker cp nginx:/etc/nginx/conf.d /app/nginx/conf/conf.d
docker cp nginx:/usr/share/nginx/html /app/nginx
docker stop nginx
docker rm nginx
docker rm -f nginx
docker run \
-p 9001:80 \
--name nginx \
-v /app/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /app/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /app/nginx/log:/var/log/nginx \
-v /app/nginx/html:/usr/share/nginx/html \
-d harbor.dscloud.com:8443/library/nginx:1.23.1
案例五:
配置文件路径:
/usr/local/etc/redis/redis.conf
运行容器
不加密码
docker run -d --name redis2 -p 6379:6379 swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/redis:6.2.7
动态设置密码
redis-cli
进去后设置
CONFIG SET requirepass "li123456"
查看信息
info
增加标签设置
docker tag swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/redis:6.2.7 docker.io/redis:6.2.7
提前准备好redis.conf文件,放到/app/src/redis中
docker run -p 6379:6379 --name redis2 -v /app/src/redis/redis.conf:/etc/redis/redis.conf -v /app/src/redis/data:/var/lib/redis -v /app/src/redis/logs:/logs -d redis:6.2.7 redis-server /etc/redis/redis.conf