1 安装docker
网上都有,这一点不必赘述
问题: 配置完成后,进行拉取软件,有时会遇到
Error response from daemon: Get “https://registry-1.docker.io/v2/“: net/http: request cancele
1. 1 修改镜像源
修改docker镜像源:
vim /etc/docker/daemon.json
{
"registry-mirrors": [
"https://2a6bf1988cb6428c877f723ec7530dbc.mirror.swr.myhuaweicloud.com",
"https://docker.m.daocloud.io",
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com",
"https://your_preferred_mirror",
"https://dockerhub.icu",
"https://docker.registry.cyou",
"https://docker-cf.registry.cyou",
"https://dockercf.jsdelivr.fyi",
"https://docker.jsdelivr.fyi",
"https://dockertest.jsdelivr.fyi",
"https://mirror.aliyuncs.com",
"https://dockerproxy.com",
"https://mirror.baidubce.com",
"https://docker.m.daocloud.io",
"https://docker.nju.edu.cn",
"https://docker.mirrors.sjtug.sjtu.edu.cn",
"https://docker.mirrors.ustc.edu.cn",
"https://mirror.iscas.ac.cn",
"https://docker.rainbond.cc"
]
}
systemctl daemon-reload
systemctl restart docker
1. 2 修改DNS配置
vim /etc/resolv.conf
增加
nameserver 114.114.114.114
此时,也许不能使用 docker search 软件 的版本,但是能够进行pull
2 dock-compose编排
version: "3.8"
services:
nginx:
image: nginx
container_name: web
ports:
- "80:80"
volumes:
./nginx/nginx.conf:/etc/nginx/nginx.conf
./nginx/conf.d:/etc/nginx/conf.d
networks:
- net1
serverjar:
image: serverjar
container_name: serverjar
ports:
- "8888:8888"
networks:
- net1
rabbitmq:
image: rabbitmq:management
container_name: rabbitmq
节点名 rabbit@rabbitserver,不然会去容器ID
hostname: rabbitserver
environment:
默认虚拟机名
RABBITMQ_DEFAULT_VHOST: admin_vhost
用户名
RABBITMQ_DEFAULT_USER: guest
密码
RABBITMQ_DEFAULT_PASS: guest
ports:
"5672:5672"
"15672:15672"
volumes:
- ./rabbitmq/data:/var/lib/rabbitmq
networks:
- net1
postgresql:
image: postgres
container_name: postgresql
environment:
POSTGRES_DB: postgres POSTGRES_USER: "root" POSTGRES_PASSWORD: "root"
ports:
- 5432:5432
networks:
- net1
volumes:
- ./postgres/data:/var/lib/postgresql/data
redis:
image: redis
container_name: redis
ports:
- '6379:6379'
volumes:
- ./redis/data:/data - ./redis/conf:/etc/redis/ - ./redis/logs:/logs
command: ["redis-server","/etc/redis/redis.conf"]
networks:
net1:
docker compose up 便依次启动
2.1 nginx
docker pull nginx //下载nginx
复制主要的文件
将自己的前端包放在html下
2.2 redis
拉取镜像 docker pull redis
创建redis专用目录 mkdir -p redis/{conf,data}
创建配置文件 vim redis/conf/redis.conf
#允许任何主机访问redis
bind 127.0.0.1
#禁用保护模式
protected-mode no
#端囗6379(默认)
port 6379
#不允许守护进程模式(设置允许与参数-d冲突,容器无法启动)
daemonize no
#访问密码
requirepass 123456
2.3 制作java镜像
链接:https://pan.baidu.com/s/1EXzmM2iTEBsLiID9zgREFg
提取码:xuxq
mdkir jdk
将网盘下载的资源包jdk-8u131-linux-x64.tar.gz 放在jdk文件夹下,
vim Dockerfile
FROM centos:centos7
RUN mkdir /usr/local/jdk (如果存在该目录不需执行此步)
WORKDIR /usr/local/jdk
ADD jdk-8u131-linux-x64.tar.gz /usr/local/jdk
ENV JAVA_HOME /usr/local/jdk/jdk1.8.0_131
ENV JRE_HOME /usr/local/jdk/jdk1.8.0_131/jre
ENV PATH $JAVA_HOME/bin:$PATH
构建镜像 docker build -t jdk:1.8 .
2.4 构建微服务镜像serverjar
vim Dockerfile
FROM jdk:1.8
COPY jar1 /jar/
EXPOSE 8888
COPY start.sh /jar/start.sh
RUN chmod +x /jar/start.sh
ENTRYPOINT ["sh","/jar/start.sh"]
start.sh 可以写
#!/bin/sh
java -jar jar1 & sleep 60 &
java -jar jar2
& sleep 60 & 是为了两个包之间间隔60s启动,也可以不需要
docker build -t serverjar .
版权归原作者 云淡风轻的小白 所有, 如有侵权,请联系我们删除。