Dockerfile:用来构建docker镜像的文本文件,是由一条条构建镜像所需的指令和参数构成的脚本
FROM centos #基础镜像centos
MAINTAINER Sevon<1169348394@qq.com> #作者和邮箱
ENV MYPATH /usr/local #设置环境变量
WORKDIR $MYPATH #指定在创建容器后,终端默认登录的进来工作目录,一个落脚点
# 安装vim编辑器
RUN yum -y install vim
# 安装ifconfig命令查看网络ip
RUN yum -y install net-tools
# 安装java8及lib库
RUN yum -y install glibc.i686
RUN mkdir /usr/local/java
# ADD是相对路径jar,把jdk-8u171-linux-x64.tar.gz添加到容器中,安装包必须和Dockerfile文件在同一位置
ADD jdk-8u171-linux-x64.tar.gz /usr/local/java/
# 配置java环境变量
ENV JAVA_HOME /usr/local/java/jdk1.8.0_171
ENV JRE_HOME $JAVA_HOME/jre
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
ENV PATH $JAVA_HOME/bin:$PATH
EXPOSE 80
CMD echo $MYPATH
CMD echo "success...ok"
CMD /bin/bash
docker 网路管理和容器调用之间的规划。容器间的互联和通信以及端口映射,容器IP变动时候可以通过服务名直接网络通信而不受到影响
docker net ls
NETWORK ID NAME DRIVER SCOPE
0e90e9ce01bb bridge bridge local
491e6cd7bd02 cig_default bridge local
a016b1213d05 host host local
f894992777e6 none null local
98eb963d7c95 sevon_network bridge local
docker network create aa_network
docker network rm aa_network
docker network inspect sevon_network
[
{
"Name": "sevon_network",
"Id": "98eb963d7c9532634202fef52fe4437dcdc82dc236874c0885287fdf359e13fa",
"Created": "2023-03-20T11:19:04.778700432+08:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.18.0.0/16",
"Gateway": "172.18.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {},
"Labels": {}
}
]
docker-compose是docker官方的开源项目,负责实现对docker容器集群的快速编排。compose是docker公司推出的一个工具软件,可以管理多个docker容器组成一个应用。需要定义一个YAML格式的配置文件docker-compose.yaml,写出好多个容器之间的调用关系。然后,只要一个命令,就能同时启动/关闭这些容器。
官网地址
官网下载
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.16.0/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
docker compose version
version:"3"
services:
microService:
image: sevon_dockerdemo:2.0
container_name:ms01
ports:
- "9092:9092"
volumes:
- /app/microService:/data
networks:
- atguigu_net
depends_on:
- redis
- mysql
redis:
image:redis:6.2.11
ports:
- "6379:6379"
volumes:
- /app/redis/redis.conf:/etc/redis/redis.conf
- /app/redis/data:/data
networks:
- atguigu_net
command: redis-server /etc/redis/redis.conf
mysql:
image:mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: 'Zhang0727'
MYSQL_ALLOW_EMPTY_PASSWORD: 'no'
MYSQL_DATASE: 'atguigudb'
MYSQL_USER: 'root'
MYSQL_PASSWORD: 'Zhang0727'
ports:
- "3306:3306"
volumes:
- /app/mysql/db:/var/lib/mysql
- /app/mysql/conf/my.cnf:/etc/my.cnf
- /adpp/mysql/init:/docker-entrypoint-initdb.d
networks:
- atguigu_net
command: --default-authentication-plugin=mysql_native_password #解决外部无法访问
networks:
atguigu_net:
轻量级的应用,提供了图形化界面,用于方便的管理Docker环境,包括单机环境和集群环境
官网地址
官网下载
运行:docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
访问:http://xxx.xx.xx.xx:9000/
version: '3.1'
volumes:
grafana_data: {}
services:
influxdb:
image: tutum/influxdb:0.9
restart: always
environment:
- PRE_CREATE_DB=cadvisor
ports:
- "8083:8083"
- "8086:8086"
volumes:
- ./data/influxdb:/data
cadvisor:
image: google/cadvisor
links:
- influxdb:influxsrv
command: -storage_driver=influxdb -storage_driver_db=cadvisor -storage_driver_host=influxsrv:8086
restart: always
ports:
- "8080:8080"
volumes:
- /:/rootfs:ro
- /var/run:/var/run:rw
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
grafana:
user: "104"
image: grafana/grafana
user: "104"
restart: always
links:
- influxdb:influxsrv
ports:
- "3000:3000"
volumes:
- grafana_data:/var/lib/grafana
environment:
- HTTP_USER=admin
- HTTP_PASS=admin
- INFLUXDB_HOST=influxsrv
- INFLUXDB_PORT=8086
- INFLUXDB_NAME=cadvisor
- INFLUXDB_USER=root
- INFLUXDB_PASS=root
docker compose config -q #没有消息就是好消息
docker-compose up -d #后台启动,推荐使用
✨ 原创不易,还希望各位大佬支持一下 \textcolor{blue}{原创不易,还希望各位大佬支持一下} 原创不易,还希望各位大佬支持一下
点赞,你的认可是我创作的动力! \textcolor{green}{点赞,你的认可是我创作的动力!} 点赞,你的认可是我创作的动力!
⭐️ 收藏,你的青睐是我努力的方向! \textcolor{green}{收藏,你的青睐是我努力的方向!} 收藏,你的青睐是我努力的方向!
✏️ 评论,你的意见是我进步的财富! \textcolor{green}{评论,你的意见是我进步的财富!} 评论,你的意见是我进步的财富!