docker常用脚本及工具
# 安装
https://docs.docker.com/install/linux/docker-ce/ubuntu/
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
# 启动及安装
build.sh
#!/bin/bash
# 使用说明:
# 启动脚本:sudo bash ./docker/build.sh
sudo docker build -t etag -f docker/Dockerfile .
1
2
3
4
5
2
3
4
5
start.sh
#!/bin/bash
# 使用说明:
# 启动脚本:sudo bash ./docker/start.sh
sudo docker-compose -p etag-compose -f docker/docker-compose.yml restart
1
2
3
4
5
2
3
4
5
stop.sh
#!/bin/bash
# 使用说明:
# 启动脚本:sudo bash ./docker/stop.sh
sudo docker-compose -p etag-compose -f docker/docker-compose.yml stop
1
2
3
4
5
2
3
4
5
install.sh
#!/bin/bash
# 使用说明:
# 启动脚本:sudo bash ./docker/start.sh
sudo mkdir -p /srv/etag/config/
sudo mkdir -p /srv/etag/mysql/
sudo cp -r ./docker/config/ /srv/etag/
sudo cp -r ./docker/mysql/init/ /srv/etag/mysql/
sudo docker-compose -p etag-compose -f docker/docker-compose.yml stop
sudo docker-compose -p etag-compose -f docker/docker-compose.yml rm
sudo docker-compose -p etag-compose -f docker/docker-compose.yml up -d
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash
#sudo dpkg -i ./docker/docker_install/docker-ce_17.09.0-ce-0-ubuntu_amd64.deb
#sudo dpkg -i ./docker/docker_install/libltdl7_2.4.6-0.1_amd64.deb
#sudo cp ./docker/docker_install/docker-compose /usr/local/bin/docker-compose
#sudo chmod +x /usr/local/bin/docker-compose
#sudo docker load < ./docker/images/redis:5-alpine.tar.gz
#sudo docker load < ./docker/images/mysql:5.7.24.tar.gz
#sudo docker load < ./docker/images/etag:1.1.1.tar.gz
# 使用说明:
# 启动脚本:sudo bash ./docker/start.sh
sudo mkdir -p /srv/etag/config/
sudo mkdir -p /srv/etag/mysql/
sudo cp -r ./docker/config/ /srv/etag/
sudo cp -r ./docker/mysql/init/ /srv/etag/mysql/
sudo docker-compose -p etag-compose -f docker/docker-compose.yml stop
sudo docker-compose -p etag-compose -f docker/docker-compose.yml rm
sudo docker-compose -p etag-compose -f docker/docker-compose.yml up -d
#sudo docker-compose -p etag-compose -f docker/docker-compose.yml rm -f
# sudo docker save redis:5-alpine | gzip > images/redis:5-alpine.tar.gz
# sudo docker save mysql:5.7.24 | gzip > images/mysql:5.7.24.tar.gz
# sudo docker save etag:1.1.1 | gzip > images/etag:1.1.1.tar.gz
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 常用软件的安装
redis, mysql, mongo, nginx,centos
docker run -p 6379:6379 -v $PWD/data:/data -d redis:4.0-aplia redis-server --appendonly yes
docker run -p 27017:27017 -v $PWD/db:/data/db -d mongo:3.4
docker run -p 27017:27017 -v ~/tmp/mongo3:/data/db -d mongo:3.4
docker run -p 3306:3306 --name mymysql -v $PWD/conf/my.cnf:/etc/mysql/my.cnf -v $PWD/logs:/logs -v $PWD/data:/mysql_data -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6
docker run -p 80:80 --name mynginx -v $PWD/www:/www -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf -v $PWD/logs:/wwwlogs -d nginx
docker run -itd -v $PWD/dockerV:/samy/dockerV --name centos centos:centos7 bash
docker exec -it centos bash
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
参照:https://www.runoob.com/docker
# docker 移除脚本及打包
remove_stop_docker.sh
#!/bin/bash
echo "正在停止所有docker里面的容器ing..."
docker stop $(docker ps -a -q)
echo "停止成功,正在删除容器ing..."
docker rm $(docker ps -a -q)
dockerlist=`docker images`
echo "$dockerlist"
docker rmi $(docker images -q)
echo "清除所有镜像完毕"
echo "正在进行新的文件打包部署..."
cd docker/Adventure
mvn package docker:build
echo "打包构建成功"
docker run -p 80:80 -t adventure/docker
echo `docker ps`
echo "end ..."
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 日志查看及清除脚本
docker_log_size.sh
#!/bin/sh
echo "======== docker containers logs file size ========"
logs=$(find /var/lib/docker/containers/ -name *-json.log)
for log in $logs
do
ls -lh $log
done
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
clean_docker_log.sh
#!/bin/sh
echo "======== start clean docker containers logs ========"
logs=$(find /var/lib/docker/containers/ -name *-json.log)
for log in $logs
do
echo "clean logs : $log"
cat /dev/null > $log
done
echo "======== end clean docker containers logs ========"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
清理日志脚本
#!/bin/sh
# chmod +x dk_log_clean.sh
# ./dk_log_clean.sh
echo -e "\033[44;37m 本机docker容器日志大小如下 \033[0m"
logs=$(find /var/lib/docker/containers/ -name *-json.log*)
for log in $logs
do
ls -sh $log
done
echo -e "\033[44;37m 开始清理docker容器日志 \033[0m"
for log in $logs
do
cat /dev/null > $log
done
echo -e "\033[44;37m 清理完毕 \033[0m"
for log in $logs
do
ls -sh $log
done
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 常用docker工具
# portainer
docker run -d -p 9999:9000 \
--restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
--name portainer-adm \
docker.io/portainer/portainer
# 访问, pwd,portainer
#http://192.168.11.17:9999
1
2
3
4
5
6
7
2
3
4
5
6
7
# bull-ui
默认集成的项目有redis超时问题,待修复;默认密码详见;me
#从Registry中拉取镜像
$ sudo docker pull registry.cn-shenzhen.aliyuncs.com/samy/bull-arena:[镜像版本号]
#将镜像推送到Registry
$ sudo docker login --username=xxx@qq.com registry.cn-shenzhen.aliyuncs.com
$ sudo docker tag [ImageId] registry.cn-shenzhen.aliyuncs.com/samy/bull-arena:[镜像版本号]
$ sudo docker push registry.cn-shenzhen.aliyuncs.com/samy/bull-arena:[镜像版本号]
sudo docker tag registry.cn-shenzhen.aliyuncs.com/samy/bull-arena bull-arena
sudo docker rmi registry.cn-shenzhen.aliyuncs.com/samy/bull-arena
sudo docker images
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
管理脚本 start.sh
#!/bin/bash
sudo docker stop bull-ui
sudo docker rm bull-ui
sudo docker run -d --restart=always --name bull-ui -p 5678:5678 -v $PWD/config/index.json:/opt/arena/src/server/config/index.json bull-arena
#docker run -d --name bull-ui -p 4567:4567 -v $PWD/config/bull_ui.json:/opt/arena/src/server/config/index.json mixmaxhq/arena
# sudo chmod +x start.sh
# ./start.sh
# http://192.168.11.17:5678
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
docker模式下运行; 记得先配置nginx的bind为自己及内网的IP地址;得考虑容器访问外部redis ip的方式兼容本地模式; 不同于直接运行项目的方式;
config/index.json
#如果是按照启动容器的方式,host不能设置为local或者127.0.0.1,应该设置为内网ip;可以设置在本地范围服务器上的,开发对应的ip范围;
{
"queues": [
{
"db":10,
"hostId": "etag",
"name": "192.168.11.41"
},
{
"db":10,
"hostId": "etag",
"name": "etag_task"
},
{
"db":10,
"hostId": "etag",
"name": "etag_common"
}
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# puppeteer
用于生产图片及pdf pdf:htmltopdf
添加多余的字体;
docker exec -it url2pdf /bin/bash
apt-get update
apt-get install -yq fonts-symbola # 🙄🙄🙄
apt-get install -yq fonts-noto-cjk # 囍, 언문, にほんご
apt-get install -yq fonts-ocr-b # PASSPORT FONT
1
2
3
4
5
2
3
4
5
https://github.com/alvarcarto/url-to-pdf-api [推荐] 可做成自己的全面截图功能
Supports optional x-api-key authentication. (API_TOKENS env var)
URL to PDF Microservice
Converts any URL or HTML content to a PDF file or an image (PNG/JPEG)
https://github.com/microbox/node-url-to-pdf-api #这个封装的不好
https://github.com/anthonylau/url-to-pdf-api/blob/master/Dockerfile #推荐用这个容器,[可做成自己的微服务]
#!/bin/bash
docker stop url2pdf
docker rm url2pdf
docker run -d --name url2pdf -p 6789:80 microbox/node-url-to-pdf-api #目前用这个;
docker run -d --name url2pdf -p 6789:80 anthonylau/node-url-to-pdf-api
# find ip of docker container
export URL2PDF=`docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' url2pdf`
# call api and download rendered pdf file;命令行方式调用,方便其他地方调用,[后面再做成微服务,多容器部署];
wget http://$URL2PDF/api/render?url=https://github.com -O github.pdf
curl -o html.pdf -XPOST -d'{"html": "<body>test</body>"}' -H"content-type: application/json" https://url-to-pdf-api.herokuapp.com/api/render
http://192.168.11.17:6789/api/render?url=https://github.com
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
dockerfile
sudo docker build -t url-to-pdf-api .
docker run -d --name url2pdf -p 6789:9000 url-to-pdf-api
#再发布阿里容器中
#docker-compose.dev.yml
version: '3'
services:
url-to-pdf-api:
build: .
image: url-to-pdf-api
environment:
- ALLOW_HTTP=true
# - NODE_ENV=development
# PORT: 9000
# ALLOW_HTTP: "true"
ports:
- "9000:9000"
volumes:
- .:/home/pptruser
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
方式一: alpine ;https://github.com/alexsergeyev/url-to-pdf-api/blob/master/Dockerfile 还有配置volume,docke-copose中
FROM node:10-alpine
RUN addgroup -S pptruser && adduser -S -g pptruser pptruser \
&& mkdir -p /home/pptruser/Downloads \
&& chown -R pptruser:pptruser /home/pptruser
RUN apk update && apk upgrade && \
echo @edge http://nl.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories && \
echo @edge http://nl.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories && \
apk add --no-cache \
chromium@edge \
nss@edge \
freetype@edge \
harfbuzz@edge \
ttf-freefont@edge
# Tell Puppeteer to skip installing Chrome. We'll be using the installed package.
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
ENV CHROME_PATH /usr/bin/chromium-browser
# Run everything after as non-privileged user.
USER pptruser
ENV HOST 0.0.0.0
WORKDIR /home/pptruser
COPY package.json package-lock.json ./
RUN npm install
EXPOSE 9000
CMD [ "node", "src/index.js"]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
方式二: ubuntu https://github.com/anthonylau/url-to-pdf-api/blob/master/Dockerfile ,也推荐,正常方式镜像;
这种方式可以控制docker里面想要的配置相应版本;官方推荐用这个镜像处理;
https://github.com/microbox/node-url-to-pdf-api/blob/master/debian/Dockerfile
ARG CHROMIUM_VERSION
FROM microbox/chromium-headless:$CHROMIUM_VERSION
ARG CHROMIUM_VERSION
ARG NODE_VERSION
MAINTAINER Ling <x@e2.to>
RUN apt-get update -y && apt-get install -yq fontconfig fonts-dejavu && rm -rf /var/lib/apt/lists/*
ADD node-v${NODE_VERSION}-linux-x64/bin/node /bin
COPY url-to-pdf-api /root
ENV CHROMIUM_VERSION=$CHROMIUM_VERSION \
NODE_VERSION=$NODE_VERSION \
NODE_ENV=production \
PORT=80 \
ALLOW_HTTP=true \
PUPPETEER_CHROMIUM_PATH=/bin/chromium
EXPOSE 80
ENTRYPOINT ["/bin/node", "src/index.js"]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
上次更新: 2022/04/15, 05:41:30