该镜像总结, 适合有一定docker基础的同学阅读
docker run --rm -dit -p 80:80 vulnerables/web-dvwa:1.9
配置文件位置:/usr/local/apache2/conf/httpd.conf
前端页面为位置:/usr/local/apache2/htdocs/
docker run -dit -p 80:80 --name apache \
-v /data/containers/apache:/usr/local/apache2/htdocs/ \
httpd:2.4
添加测试页面
echo "111" >> /data/containers/apache/index.html
docker run -p 80:80 -p 443:443 --name nginx \
-v /data/containers/nginx/log:/var/log/nginx \
-v /data/containers/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /data/containers/nginx/html:/usr/share/nginx/html \
-v /data/containers/nginx/ssl:/etc/nginx/ssl \
-v /etc/localtime:/etc/localtime:ro \
-d nginx:1.14.2
-v /data/containers/nginx/log:/var/log/nginx 映射nginx日志存放位置
-v /data/containers/nginx/conf/nginx.conf:/etc/nginx/nginx.conf 映射nginx配置文件
-v /data/containers/nginx/html:/usr/share/nginx/html 映射静态页面位置
-v /data/containers/nginx/ssl:/etc/nginx/ssl 映射证书位置
-v /etc/localtime:/etc/localtime:ro 同步容器和宿主机的时间
注: 我们经常将多个端口开在一个nginx中可以使用–net=host让nginx和宿主机共享端口
docker run --name nginx \
--net=host \
-v /data/containers/nginx/log:/var/log/nginx \
-v /data/containers/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /data/containers/nginx/html:/usr/share/nginx/html \
-v /data/containers/nginx/ssl:/etc/nginx/ssl \
-v /etc/localtime:/etc/localtime:ro \
-d nginx:1.14.2
1.有时我们用只需要java -jar就可以运行起我们的服务,因此我们只需要一个带java环境的docker镜像
Dockerfile
FROM centos:7
MAINTAINER sleepy<[email protected]>
ENV JAVA_HOME /opt/jdk1.8.0_212
ENV PATH $JAVA_HOME/bin:$PATH
CMD ["/bin/bash"]
2.自己建立好的java:8镜像地址,该镜像已经公开,大家可以直接进行使用,使用方法参照3
registry.cn-shanghai.aliyuncs.com/sleepy/java:8
3.当然如果配置了阿里云镜像可以直接使用 java:8
docker run -p 8080:8080 --name server \
-v /data/containers/server/:/data/ \
-v /etc/localtime:/etc/localtime:ro \
-d java:8 java -jar /dataserver.jar
-v /data/containers/server/:/data/ jar包存放的位置
docker-mysql:5.7的安装
注:如果有这些目录一定要删除
docker run -d -p 3306:3306 --name mysql \
-e MYSQL_USER="test" \
-e MYSQL_PASSWORD="test" \
-e MYSQL_ROOT_PASSWORD=root \
-v /data/containers/mysql/conf:/etc/mysql/conf.d \
-v /data/containers/mysql/logs:/logs \
-v /data/containers/mysql/data:/var/lib/mysql \
mysql:5.7
-e MYSQL_ROOT_PASSWORD=root 指定root账户的密码为root
-v /data/containers/mysql/conf:/etc/mysql/conf.d \ msyql配置文件
-v /data/containers/mysql/logs:/logs \ 日志文件
-v /data/containers/mysql/data:/var/lib/mysql \ 数据存放位置
创建msyql8.0
docker run -d -p 3306:3306 --name mysql8 \
-e MYSQL_ROOT_PASSWORD=root \
-v /data/containers/mysql8/conf:/etc/mysql/conf.d \
-v /data/containers/mysql8/logs:/logs \
-v /data/containers/mysql8/data:/var/lib/mysql \
mysql:8.0
Navicat Premium 12连接MySQL数据库出现Authentication plugin ‘caching_sha2_password’ cannot be loaded的解决方案
很多用户在使用Navicat Premium 12连接MySQL数据库时会出现Authentication plugin ‘caching_sha2_password’ cannot be loaded的错误,解决方法如下
docker exec -it mysql8 /bin/bash
mysql -u root -proot
ALTER USER 'root'@'%' IDENTIFIED BY 'root' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
FLUSH PRIVILEGES; #刷新权限
docker run -d --name activemq -p 61617:61616 -p 8162:8161 \
-v /data/containers/activemq/data:/data \
-v /data/containers/activemq/log:/var/log/activemq \
webcenter/activemq:5.14.3
docker run -p 6379:6379 --name redis \
-v /data/containers/redis/conf/redis.conf:/etc/redis/redis.conf \
-v /data/containers/redis/redis-data:/data \
-v /etc/localtime:/etc/localtime:ro \
-d redis:5.0.4 redis-server /etc/redis/redis.conf \
--appendonly yes
-v /data/containers/redis/conf/redis.conf:/etc/redis/redis.conf \ 指定redis配置文件
-v /data/containers/redis/redis-data:/data \ 指定redis 日志 和 持久化目录
-v /etc/localtime:/etc/localtime:ro \ 同步主机时间
edis-server /etc/redis/redis.conf \ 指定配置文件进行启动
–appendonly yes 开启持久化rdb aof
安装mysql
docker run -d -p 3306:3306 --name mysql \
-e MYSQL_ROOT_PASSWORD=root \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="zabbix" \
-e MYSQL_DATABASE="zabbix" \
-v /data/containers/mysql/conf:/etc/mysql/conf.d \
-v /data/containers/mysql/logs:/logs \
-v /data/containers/mysql/data:/var/lib/mysql \
-v /etc/localtime:/etc/localtime:ro \
mysql:5.7 \
--character-set-server=utf8 --collation-server=utf8_bin
安装zabbix-server-mysql
docker run -d --name zabbix-server-mysql \
--net=host \
-e DB_SERVER_HOST="192.168.1.2" \
-e DB_SERVER_PORT="3306" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="zabbix" \
-e MYSQL_DATABASE="zabbix" \
-v /data/containers/zabbix/alertscripts:/usr/lib/zabbix/alertscripts \
-v /data/containers/zabbix/externalscripts:/usr/lib/zabbix/externalscripts \
-v /etc/localtime:/etc/localtime:ro \
zabbix/zabbix-server-mysql:centos-4.2-latest
拷贝server中的表还原至mysql中
#拷贝server中的表结构到宿主机
docker cp zabbix-server-mysql:/usr/share/doc/zabbix-server-mysql \
/data/containers/zabbix/
#放入到mysql容器中
docker cp /data/containers/zabbix mysql:/
#还原表
docker exec -it mysql /bin/bash
cd /zabbix
zcat create.sql.gz | mysql -uroot -p zabbix
#检查库是否还原成功-也可以navicat直接看
mysql -uroot -proot
use zabbix;
show tables;
exit;
安装zabbix-web-apache/nginx-mysql
docker run -p 80:80 -p 443:443 --name zabbix-web-nginx-mysql \
-e DB_SERVER_HOST="192.168.1.2" \
-e DB_SERVER_PORT="3306" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="zabbix" \
-e ZBX_SERVER_HOST="192.168.1.2" \
-e PHP_TZ="Asia/Shanghai" \
-v /etc/localtime:/etc/localtime:ro \
-d zabbix/zabbix-web-nginx-mysql:centos-4.2-latest
安装zabbix-agent
#端口可以更换 10053:10050
ZBX_HOSTNAME是客户端ip地址
脚本位置/etc/zabbix/zabbix_agentd.d/
配置文件位置 /etc/zabbix/zabbix_agentd.conf
#不带脚本目录映射
docker run -p 10050:10050 --name zabbix-agent \
-e ZBX_SERVER_HOST="192.168.1.2" \
-e ZBX_HOSTNAME="192.168.1.2" \
-v /etc/localtime:/etc/localtime:ro \
--privileged -d zabbix/zabbix-agent:centos-4.2-latest
#带脚本目录映射的
docker run -p 10050:10050 --name zabbix-agent \
-e ZBX_SERVER_HOST="192.168.1.2" \
-e ZBX_HOSTNAME="192.168.1.2" \
-v /data/containers/zabbix-agent/zabbix_agentd.d/:/etc/zabbix/zabbix_agentd.d/ \
-v /etc/localtime:/etc/localtime:ro \
--privileged -d zabbix/zabbix-agent:centos-4.2-latest