常用的 dokcer 环境与项目配置
常用的 dokcer 环境与项目配置
docker基本配置
网络访问问题
# 后台执行 socat 端口转发
(socat TCP-LISTEN:15246,reuseaddr,fork TCP:localhost:15236) &
# 设置终端网络代理
export https_proxy=http://10.10.10.4:15246 http_proxy=http://10.10.10.4:15246 all_proxy=http://10.10.10.4:15246
国区docker镜像
docker中国官方镜像 https://registry.docker-cn.com
Azure 中国镜像 https://dockerhub.azk8s.cn
网易云镜像 https://hub-mirror.c.163.com
阿里云 https://<你的ID>.mirror.aliyuncs.com 需要去阿里云申请,免费的
腾讯云 https://mirror.ccs.tencentyun.com
百度云 https://mirror.baidubce.com
必备的docker项目
nginx && jekyll
拉镜像、建目录
# 拉取镜像
docker pull nginx
# 创建nginx映射目录
mkdir -p ~/nginx/www ~/nginx/logs ~/nginx/conf/conf.d
生成并复制nginx.conf
# 运行demo容器,生成nginx.conf
docker run --name runoob-nginx-test -p 8081:80 -d nginx
# 复制
sudo docker cp 55ff0ee131d:/etc/nginx/nginx.conf /volume1/docker/nginx/conf
# 停止demo容器并清除掉
docker container stop runoob-nginx-test
docker container prune
# 进入容器内的bash
docker exec -it wg-easy /bin/bash
创建前台网络
docker network create net-front
创建jekyll容器并启动
mkdir -p /volume1/docker/jekyll/vendor/bundle
cd /volume1/docker/jekyll
# 先进bash
docker run --rm --name my-jekyll \
--network net-front \
--volume="$PWD:/srv/jekyll" \
--volume="$PWD/vendor/bundle:/usr/local/bundle" \
-p 4000:4000 \
-it jekyll/jekyll:3.8 \
bash
# 再手动装依赖
$ bundle install
# 后台运行
docker run -d --name my-jekyll \
--restart=always \
--network net-front \
--volume="$PWD:/srv/jekyll" \
--volume="$PWD/vendor/bundle:/usr/local/bundle" \
-p 4000:4000 \
-it jekyll/jekyll:3.8 \
jekyll serve --watch --drafts --incremental
创建nginx容器并启动
cd /volume1/docker/nginx
docker run -d -p 80:80 \
--name my-nginx \
--restart=always \
--network my-web-net \
--hostname=xxx.com \
--add-host=app.xxx.com:127.0.0.1 \
-v $PWD/conf/conf.d:/etc/nginx/conf.d \
-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf \
-v $PWD/www:/usr/share/nginx \
-v $PWD/../jekyll/_site:/usr/share/nginx/jekyll \
nginx
R2S的OpenWrt上配置docker环境
nginx容器
docker run -d -p 8000:8000 \
--name my-nginx \
--restart=always \
--network bridge \
-v /root/docker/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /root/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /root/docker/nginx/www:/usr/share/nginx \
-v /root/docker/jekyll/_site:/usr/share/nginx/jekyll \
nginx
docker run --rm \
--name my-jekyll \
--network bridge \
--volume="/root/docker/jekyll:/srv/jekyll" \
--volume="/root/docker/jekyll/vendor/bundle:/usr/local/bundle" \
-p 4000:4000 \
-it jekyll/jekyll:3.8 \
bash
查看容器日志
docker logs -f 43c3d0557491
Reader web
设置代理
export https_proxy=http://192.168.11.210:15246 http_proxy=http://192.168.11.210:15246 all_proxy=192.168.11.210:15246
在synology上查看某端口占用情况
sudo netstat -tuln | grep [port_number]
docker运行
#docker run -d --restart=always --name=reader -e "SPRING_PROFILES_ACTIVE=prod" -v $(pwd)/logs:/logs -v $(pwd)/storage:/storage -p 8080:8080 hectorqin/reader
# 多用户版
#docker run -d \
--restart=unless-stopped \
--name=reader \
-v $(pwd)/logs:/logs \
-v $(pwd)/storage:/storage \
-p 8080:8080 \
hectorqin/reader java -jar /app/bin/reader.jar --spring.profiles.active=prod --reader.app.secure=true --reader.app.secureKey=Alh.350 --reader.app.inviteCode=luowei123
# 多用户版 使用环境变量
#docker run -d \
--restart=always \
--name=reader \
-e "SPRING_PROFILES_ACTIVE=prod" \
-e "READER_APP_SECURE=true" \
-e "READER_APP_SECUREKEY=Alh.350" \
-e "READER_APP_INVITECODE=luowei123" \
-v $(pwd)/logs:/logs \
-v $(pwd)/storage:/storage \
-p 4396:8080 \
hectorqin/reader
Mysql数据库搭建
docker命令
参考: Run MySQL & phpMyAdmin locally in 3 steps using Docker
创建并运行mysql容器
# 添加网络
docker network create mynet
docker run -d \
--restart always \
--name db_mysql \
--network mynet \
-e MYSQL_USER=name \
-e MYSQL_PASSWORD=name13579 \
-e MYSQL_ROOT_PASSWORD=name.13579 \
-p 3307:3306 \
mysql:8.0.1
与容器数据库交互
# 进入容器
docker exec -it db_mysql bash
# 连接mysql
mysql -u root -p
# 显示数据库
show databases;
创建并运行phpMyAdmin
docker run -d \
--name db_mysql_phpmyadmin \
--network mynet \
-e MYSQL_USER=name \
-e MYSQL_PASSWORD=name13579 \
-e MYSQL_ROOT_PASSWORD=name.13579 \
-e PMA_HOST=db_mysql \
-p 31000:80 \
phpmyadmin/phpmyadmin:latest
docker run --rm -it \
--name db_mysql_phpmyadmin \
--network mynet \
-e MYSQL_USER=name \
-e MYSQL_PASSWORD=name13579 \
-e MYSQL_ROOT_PASSWORD=name.13579 \
-e PMA_HOST=db_mysql \
-p 31000:80 \
phpmyadmin/phpmyadmin:latest
postgres数据库搭建
创建并运行postgres容器
docker run -d \
--name db_postgres \
--network mynet \
-e POSTGRES_PASSWORD=name.13579 \
-p 5433:5432 \
postgres
创建并运行pgAdmin容器
docker run -d \
--name my-pgadmin \
--network mynet \
-p 31001:80 \
-e 'PGADMIN_DEFAULT_EMAIL=name010101@gmail.com' \
-e 'PGADMIN_DEFAULT_PASSWORD=name.13579' \
dpage/pgadmin4
wiki 搭建
因镜像托管在github上,先在网速快的机器上下载再导入外网速度慢的机器上,具体操作如下:
# pull
docker pull --platform amd64 ghcr.io/requarks/wiki:2
# 导出
docker save -o jekyll-serve.tar ghcr.io/requarks/wiki:2
# 导入
docker load -i ./image/ghcr.io_requarks_wiki.tar
# 添加镜像名与标签
docker tag <id> ${repo/image_name:tag}
授权数据库
GRANT ALL PRIVILEGES ON wiki.* TO 'luowei'@'%';
wiki容器安装命令
# postgres 数据库
docker run -d \
-p 8080:3000 \
--name wiki \
--network mynet \
--restart unless-stopped \
-e "DB_TYPE=postgres" \
-e "DB_HOST=db" \
-e "DB_PORT=5432" \
-e "DB_USER=name" \
-e "DB_PASS=name13579" \
-e "DB_NAME=wiki" ghcr.io/requarks/wiki:2
docker run -d \
--name wiki \
--restart unless-stopped \
--network mynet \
-p 3000:3000 \
-e "DB_TYPE=mysql" \
-e "DB_HOST=db_mysql" \
-e "DB_PORT=3306" \
-e "DB_USER=name" \
-e "DB_PASS=name13579" \
-e "DB_NAME=wiki" \
ghcr.io/requarks/wiki:2
Chevereto图床服务搭建
相关文档:
https://chevereto-free.github.io/setup/container/compose.html#up
https://github.com/rodber/chevereto-free/blob/1.6/httpd-php.yml
数据库授权
GRANT ALL PRIVILEGES ON chevereto.* TO 'luowei'@'%';
chevereto容器安装命令
docker run -d \
--name chevereto \
--restart unless-stopped \
-p 8810:80 \
--network mynet \
-v $PWD/storage:/var/www/html/images \
-v $PWD/content:/var/www/html/content \
-e "CHEVERETO_TAG=free" \
-e "CHEVERETO_DB_HOST=db_mysql" \
-e "CHEVERETO_DB_USER=name" \
-e "CHEVERETO_DB_PASS=name13579" \
-e "CHEVERETO_DB_PORT=3306" \
-e "CHEVERETO_DB_NAME=chevereto" \
-e "CHEVERETO_DISABLE_UPDATE_HTTP=1" \
-e "CHEVERETO_DISABLE_UPDATE_CLI=1" \
-e "CHEVERETO_HTTPS=0" \
ghcr.io/rodber/chevereto-free:latest
docker run --rm -it \
--name chevereto \
-p 8810:80 \
--network mynet \
-e "CHEVERETO_TAG=free" \
-e "CHEVERETO_DB_HOST=db_mysql" \
-e "CHEVERETO_DB_USER=name" \
-e "CHEVERETO_DB_PASS=name13579" \
-e "CHEVERETO_DB_PORT=3306" \
-e "CHEVERETO_DB_NAME=chevereto" \
-e "CHEVERETO_DISABLE_UPDATE_HTTP=1" \
-e "CHEVERETO_DISABLE_UPDATE_CLI=1" \
-e "CHEVERETO_HTTPS=0" \
ghcr.io/rodber/chevereto-free:latest