curl -o /etc/yum.repos.d/docker.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install -y docker-ce
[root@vm1 ~]# systemctl start docker
[root@vm1 ~]# docker ps
[root@vm ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": [
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://registry.docker-cn.com"
],
"insecure-registries": ["192.168.1.11:6000"]
}
[root@vm ~]# systemctl daemon-reload
[root@vm ~]# systemctl restart docker
docker run -itd -p 8080:8080 tomcat:9.0.68-jdk8-corretto-al2
docker cp jenkins.war b02a7623d210:/usr/local/tomcat/webapps
docker exec -it b02a7623d210 bash
ls webapps
jenkins
#访问方式1
localhost:8080/jenkins #要加jenkins才能访问
修改访问路径
docker cp 2d300106e73d:/usr/local/tomcat/conf/server.xml .
vim server.xml
#添加此行修改目录,结尾的,具体看报错添加
打镜像
FROM tomcat:9.0.68-jdk8-corretto-al2
ADD jenkins.war /usr/local/tomcat/webapps
ENTRYPOINT ["/usr/local/tomcat/bin/catalina.sh","run"]
docker build -t jenkins:v1 .
docker run -itd -p 8080:8080 -v /root/server.xml:/usr/local/tomcat/conf/server.xml jenkins:v1
#访问方式2 localhost:8080
docker run -d \
-e PREFER_HOST_MODE=ip \
-e MODE=standalone \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=192.168.1.11 \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=123456 \
-e MYSQL_SERVICE_DB_NAME=nacos \
-e TIME_ZONE='Asia/Shanghai' \
-v /home/dockerdata/nacos2.0.3/logs:/home/nacos/logs \
-v /home/dockerdata/nacos2.0.3/conf:/home/nacos/conf \
-p 8848:8848 \
-p 9848:9848 \
-p 9849:9849 \
--name nacos2.0.3 \
--restart=always \
nacos/nacos-server:2.0.3
docker run -p 80:80 --name nginx:1.21.4 --restart=always -itd nginx:1.21.4
root@170bc8aa1ef9:/# ls /usr/share/nginx/html/
50x.html index.html
root@170bc8aa1ef9:/# ls /etc/nginx/
conf.d fastcgi_params mime.types modules nginx.conf scgi_params uwsgi_params
docker pull redis:6.2
[root@docker ~]# docker run -p 6379:6379 --name myredis -itd redis:6.2
4464521e304d2f81964b74b616aedd5baa2d3f91e9aa74b84a522f7ce1f91025
[root@docker ~]# docker exec -it 4464521e304d bash
root@4464521e304d:/data# ps
bash: ps: command not found
root@4464521e304d:/data# redis-cli
127.0.0.1:6379> ping
PONG
redis镜像里没有找到redis的conf文件,你可以使用环境变量启动
docker run --name myredis -v /root/redis/data:/data -v
/root/redis/conf/redis.conf:/etc/redis/redis.conf -d -p 6379:6379 redis redis-server
#/data数据目录
集群样式
docker run -d --name redis-node-1 --net host --privileged=true redis:6.2 --cluster-enabled yes --appendonly yes --port 6381
docker run -d --name redis-node-2 --net host --privileged=true redis:6.2 --cluster-enabled yes --appendonly yes --port 6382
docker run -d --name redis-node-3 --net host --privileged=true redis:6.2 --cluster-enabled yes --appendonly yes --port 6383
docker run -d --name redis-node-4 --net host --privileged=true redis:6.2 --cluster-enabled yes --appendonly yes --port 6384
docker run -d --name redis-node-5 --net host --privileged=true redis:6.2 --cluster-enabled yes --appendonly yes --port 6385
docker run -d --name redis-node-6 --net host --privileged=true redis:6.2 --cluster-enabled yes --appendonly yes --port 6386
[root@docker ~]# docker exec -it a5e27c524334 bash
root@docker:/data# ls
appendonly.aof nodes.conf
root@docker:/data# redis-cli --cluster create 192.168.1.11:6381 192.168.1.11:6382 192.168.1.11:6383 192.168.1.11:6384 192.168.1.11:6385 192.168.1.11:6386 --cluster-replicas 1
root@docker:/data# redis-cli --cluster check 192.168.1.11:6381
192.168.1.11:6381 (b93fef2d...) -> 0 keys | 5461 slots | 1 slaves.
192.168.1.11:6383 (4f1160be...) -> 0 keys | 5461 slots | 1 slaves.
192.168.1.11:6382 (71f5df7f...) -> 0 keys | 5462 slots | 1 slaves.
docker run --name zookeeper -p 2181:2181 -p 2888:2888 -p 3888:3888 -p 8080:8080 --restart always -d zookeeper
[root@docker ~]# docker run -d -e TZ="Asia/Shanghai" -p 2181:2181 -v /root/zookeeper:/data --name zookeeper --restart always zookeeper
root@e8947d1d8202:/apache-zookeeper-3.8.0-bin# ls
bin conf docs lib LICENSE.txt NOTICE.txt README.md README_packaging.md
root@e8947d1d8202:/apache-zookeeper-3.8.0-bin# ls bin/
README.txt zkCli.sh zkServer.cmd zkSnapshotComparer.cmd zkSnapShotToolkit.sh
zkCleanup.sh zkEnv.cmd zkServer-initialize.sh zkSnapshotComparer.sh zkTxnLogToolkit.cmd
zkCli.cmd zkEnv.sh zkServer.sh zkSnapShotToolkit.cmd zkTxnLogToolkit.sh
./bin/zkCli.sh
[zk: localhost:2181(CONNECTED) 0] ls /
[zookeeper]
[root@docker ~]# docker pull rabbitmq:3.8-management
[root@docker ~]# docker run -d --hostname docker --name rabbitmq -p 15672:15672 -p 5672:5672 rabbitmq:3.8-management
[root@vm ~]# docker pull sonatype/nexus3
[root@vm ~]# mkdir -p mkdir docker_nexus3/nexus-data
[root@vm ~]# chown -R 200 docker_nexus3/nexus-data
[root@vm ~]# chmod 777 docker_nexus3/nexus-data/
vm ~]# docker run -d --privileged=true --name=the_nexus3 -p 6000:6000 -p 8088:8081 \
-v /root/docker_nexus3/nexus-data:/nexus-data sonatype/nexus3
#-e INSTALL4J_ADD_VM_PARAMS="-Xms256M -XX:MaxDirectMemorySize=2048M" \
[root@vm ~]# cat docker_nexus3/nexus-data/admin.password
192.168.1.11:8088 admin/passwd
权限管理不再介绍
https://blog.csdn.net/sasafa/article/details/126222609
点击左上角repositories->create repository。选择创建docker(hosted)。
[root@vm ~]# docker login 192.168.1.11:6000
[root@vm ~]# docker tag busybox:latest 192.168.1.11:6000/busybox:v1
[root@vm ~]# docker push 192.168.1.11:6000/busybox:v1
访问http://192.168.1.11:8088/repository/localhost/看到busybox实验ok
只需要一行命令docker compose up -d,就可以启动一个包含后端项目、前端项目、数据库的完整服务。
拉取Nginx镜像部署
docker run -d -p 80:80 -v /fronted-demo2:/usr/share/nginx/html --name frontend-test nginx
docker exec -it frontend-test /bin/bash
在项目根目录下新建nginx/default.conf
server {
listen 80;
server_name localhost;
underscores_in_headers on;
root /home/frontend;
location / {
try_files $uri $uri/ @router;
index index.html;
}
location @router {
rewrite ^.*$ /index.html last;
}
}
编写Dockerfile文件
FROM nginx
WORKDIR /home/frontend
COPY build .
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
docker build -t frontend .
docker images
docker run -d -p 80:80 --name frontend-v1 frontend
拉取并启动数据库、连接数据库
docker run -p 3306:3306 --restart=always --privileged=true --name mysql -v /Users/user/Desktop/mysql/data:/var/lib/mysql -v /Users/user/Desktop/mysql/my.cnf:/etc/mysql/my.cnf -e MYSQL_ROOT_PASSWORD="123456" -d mariadb
编写docker-compose配置文件
version: '3'
networks:
app-web:
driver: bridge
services:
mysql:
image: mariadb
ports:
- 3306:3306
command: --default-authentication-plugin=mysql_native_password
restart: always
networks:
- app-web
environment:
- TZ=Asia/Shanghai
- MYSQL_USER=root
- MYSQL_ROOT_PASSWORD=123456
volumes:
- ./mysql/data:/var/lib/mysql
- ./mysql/my.cnf:/etc/mysql/my.cnf
- /etc/localtime:/etc/localtime
backend:
image: backend
ports:
- 9000:9000
depends_on:
- mysql
networks:
- app-web
frontend:
image: frontend
ports:
- 80:80
depends_on:
- backend