一个包含了 java环境,mysql,nginx,redis docker 镜像

  • 1.目录结构
    这里写图片描述

  • 2.softwares 目录下的软件
    这里写图片描述

  • 3.编译
# 进入到当前目录
docker build -t app:web .
  • 4.运行镜像
docker run --name web -p 1022:22 -p 13306:3306 -p 80:80 -p 16379:6379 -v /data/mysql:/data/mysql app:web
  • 5.Dockerfile
FROM centos:centos7
MAINTAINER ztd "770960546@qq.com"
# 1.准备工作创建文件夹
RUN \
    mkdir -p /opt/tools \
    && mkdir -p /etc/redis \
    && mkdir /opt/logs \
    && mkdir -p /data/mysql

# 复制文件
COPY softwares/jdk-8u102-linux-x64.tar.gz /opt/tools
COPY softwares/redis-3.2.8.tar.gz /opt/tools
COPY softwares/apache-tomcat-7.0.70.tar.gz /opt/tools
COPY redis.conf /etc/redis/redis.conf
COPY supervisord.conf /etc/supervisord.conf
COPY program.conf /etc/program.conf
# 复制数据库文件
COPY softwares/libaio-0.3.107-10.el6.x86_64.rpm /opt/tools
COPY softwares/MySQL-client-5.6.23-1.rhel5.x86_64.rpm /opt/tools
COPY softwares/MySQL-devel-5.6.23-1.rhel5.x86_64.rpm /opt/tools
COPY softwares/MySQL-server-5.6.23-1.rhel5.x86_64.rpm /opt/tools
# 复制nginx安装文件
COPY softwares/nginx-1.13.7.tar.gz /opt/tools
#COPY nginx.conf /opt/tools/nginx.conf


# 安装 sshd 修改密码
RUN \
    yum install passwd openssl openssh-server -y \
    && ssh-keygen -q -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N '' \
    && ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N '' \
    && ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key  -N '' \
    && sed -i "s/#UsePrivilegeSeparation.*/UsePrivilegeSeparation no/g" /etc/ssh/sshd_config \
    && sed -i "s/UsePAM.*/UsePAM no/g" /etc/ssh/sshd_config \
    && echo 123456 | passwd --stdin root \
    && echo root:123456|chpasswd \
    && rm -rf /var/cache/yum/*
# 安装redis
RUN \
    yum install gcc -y \
    && cd /opt/tools \
    && tar -xzf redis-3.2.8.tar.gz \
    && rm -rf redis-3.2.8.tar.gz \
    && cd redis-3.2.8 && yum -y install tcl && make && make install \
    && cd /opt/tools \
    && rm -rf redis-3.2.8 \
    && rm -rf /var/cache/yum/*
# 安装mysql
RUN \
    yum -y install perl perl-devel perl-Module-Install.noarch net-tools \
    && cd /opt/tools \
    && rpm -ivh libaio-0.3.107-10.el6.x86_64.rpm \
    && rpm -ivh MySQL-server-5.6.23-1.rhel5.x86_64.rpm \
    && rpm -ivh MySQL-client-5.6.23-1.rhel5.x86_64.rpm \
    && rpm -ivh MySQL-devel-5.6.23-1.rhel5.x86_64.rpm \
    && chown -R mysql:mysql /data/mysql \
    && /etc/init.d/mysql start \
    && mysqltmppwd=`cat /root/.mysql_secret | cut -b 87-102` \
    && mysqladmin -u root -p${mysqltmppwd} password "123456" \
    && mysql -uroot -p123456 -e"grant all privileges on *.* to root@'%' identified by '123456' with grant option" \
    && mysql -uroot -p123456 -e"flush privileges" \
    && /etc/init.d/mysql stop \
    && rm -rf libaio-0.3.107-10.el6.x86_64.rpm \
    && rm -rf MySQL-client-5.6.23-1.rhel5.x86_64.rpm \
    && rm -rf MySQL-devel-5.6.23-1.rhel5.x86_64.rpm \
    && rm -rf MySQL-server-5.6.23-1.rhel5.x86_64.rpm \
    && rm -rf /var/cache/yum/* \
    && sed -i -e "10a datadir = /data/mysql" /usr/my.cnf

# 安装 nginx
RUN \
    yum -y install gcc-c++ zlib zlib-devel openssl openssl--devel pcre pcre-devel \
    && cd /opt/tools \
    && tar -zxv -f nginx-1.13.7.tar.gz \
    && rm -rf nginx-1.13.7.tar.gz \
    && cd nginx-1.13.7 \
    && ./configure --with-http_stub_status_module \
    && make && make install \
    && cd .. \
    && rm -rf nginx-1.13.7 \
    && rm -rf /var/cache/yum/*
#   && echo "daemon off" >> /usr/local/nginx/conf/nginx.conf
#   && cp -rf /opt/tools/nginx.conf /usr/local/nginx/conf/nginx.conf


# 安装supervisor
RUN \
    yum -y install python-setuptools \
    && easy_install supervisor \
    && rm -rdf /var/cache/yum/*


# 设置java环境变量
RUN \
    cd /opt/tools \
        && tar -zxvf jdk-8u102-linux-x64.tar.gz \
        && rm -rf jdk-8u102-linux-x64.tar.gz \
        && tar -zxvf apache-tomcat-7.0.70.tar.gz \
        && rm -rf apache-tomcat-7.0.70.tar.gz \
    && echo 'export JAVA_HOME=/opt/tools/jdk1.8.0_102' >> /etc/profile \
    && echo 'export PATH=$JAVA_HOME/bin:$PATH' >> /etc/profile \
    && echo 'export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar' >> /etc/profile \
    && source /etc/profile
# 设置环境变量

EXPOSE 22 80 3306 6379
CMD /usr/bin/supervisord -c /etc/supervisord.conf
#CMD /usr/sbin/init
  • 6.program.conf
[program:mysql]
command=mysqld --user=mysql

[program:nginx]
autostart=true
autorestart=true
command=/usr/local/nginx/sbin/nginx -g "daemon off;" -c /usr/local/nginx/conf/nginx.conf

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket

[program:sshd]
command=/usr/sbin/sshd -D
autostart=true
autorestart=true

[program:redis]
tartsecs=50
command=/usr/local/bin/redis-server /etc/redis/redis.conf
  • 7.redis.conf
# 所有ip均可以访问
bind 0.0.0.0
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
# 如果这个 redis 是让 supervisorctl 来管理的,那么这个地方就需要设置为no,如果是yes的话就无法启动了
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100

appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
  • 8.supervisord.conf
[unix_http_server]
file=/tmp/supervisor.sock   ; (the path to the socket file)
;chmod=0700                 ; socket file mode (default 0700)
;chown=nobody:nogroup       ; socket file uid:gid owner
;username=user              ; (default is no username (open server))
;password=123               ; (default is no password (open server))

;[inet_http_server]         ; inet (TCP) server disabled by default
;port=127.0.0.1:9001        ; (ip_address:port specifier, *:port for all iface)
;username=user              ; (default is no username (open server))
;password=123               ; (default is no password (open server))

[supervisord]
#logfile=/opt/logs/supervisord.log ; (main log file;default $CWD/supervisord.log)
#logfile_maxbytes=2MB        ; (max main logfile bytes b4 rotation;default 50MB)
#logfile_backups=2            ; (num of main logfile rotation backups;default 10)
#loglevel=info                ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=true               ; (start in foreground if true;default false)
minfds=1024                  ; (min. avail startup file descriptors;default 1024)
minprocs=200                 ; (min. avail process descriptors;default 200)
;umask=022                   ; (process file creation umask;default 022)
;user=chrism                 ; (default is current user, required if root)
;identifier=supervisor       ; (supervisord identifier, default is 'supervisor')
;directory=/tmp              ; (default is not to cd during start)
;nocleanup=true              ; (don't clean up tempfiles at start;default false)
;childlogdir=/tmp            ; ('AUTO' child log dir, default $TEMP)
;environment=KEY="value"     ; (key value pairs to add to environment)
;strip_ansi=false            ; (strip ansi escape codes in logs; def. false)

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket
;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=chris              ; should be same as http_username if set
;password=123                ; should be same as http_password if set
;prompt=mysupervisor         ; cmd line prompt (default "supervisor")
;history_file=~/.sc_history  ; use readline history if available

; The below sample program section shows all possible program subsection values,
; create one or more 'real' program: sections to be able to control them under
; supervisor.

;[program:theprogramname]
;command=/bin/cat              ; the program (relative uses PATH, can take args)
;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
;numprocs=1                    ; number of processes copies to start (def 1)
;directory=/tmp                ; directory to cwd to before exec (def no cwd)
;umask=022                     ; umask for process (default None)
;priority=999                  ; the relative start priority (default 999)
;autostart=true                ; start at supervisord start (default: true)
;autorestart=unexpected        ; whether/when to restart (default: unexpected)
;startsecs=1                   ; number of secs prog must stay running (def. 1)
;startretries=3                ; max # of serial start failures (default 3)
;exitcodes=0,2                 ; 'expected' exit codes for process (default 0,2)
;stopsignal=QUIT               ; signal used to kill process (default TERM)
;stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)
;stopasgroup=false             ; send stop signal to the UNIX process group (default false)
;killasgroup=false             ; SIGKILL the UNIX process group (def false)
;user=chrism                   ; setuid to this UNIX account to run the program
;redirect_stderr=true          ; redirect proc stderr to stdout (default false)
;stdout_logfile=/a/path        ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups=10     ; # of stdout logfile backups (default 10)
;stdout_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
;stdout_events_enabled=false   ; emit events on stdout writes (default false)
;stderr_logfile=/a/path        ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups=10     ; # of stderr logfile backups (default 10)
;stderr_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
;stderr_events_enabled=false   ; emit events on stderr writes (default false)
;environment=A="1",B="2"       ; process environment additions (def no adds)
;serverurl=AUTO                ; override serverurl computation (childutils)

; The below sample eventlistener section shows all possible
; eventlistener subsection values, create one or more 'real'
; eventlistener: sections to be able to handle event notifications
; sent by supervisor.

;[eventlistener:theeventlistenername]
;command=/bin/eventlistener    ; the program (relative uses PATH, can take args)
;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
;numprocs=1                    ; number of processes copies to start (def 1)
;events=EVENT                  ; event notif. types to subscribe to (req'd)
;buffer_size=10                ; event buffer queue size (default 10)
;directory=/tmp                ; directory to cwd to before exec (def no cwd)
;umask=022                     ; umask for process (default None)
;priority=-1                   ; the relative start priority (default -1)
;autostart=true                ; start at supervisord start (default: true)
;autorestart=unexpected        ; whether/when to restart (default: unexpected)
;startsecs=1                   ; number of secs prog must stay running (def. 1)
;startretries=3                ; max # of serial start failures (default 3)
;exitcodes=0,2                 ; 'expected' exit codes for process (default 0,2)
;stopsignal=QUIT               ; signal used to kill process (default TERM)
;stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)
;stopasgroup=false             ; send stop signal to the UNIX process group (default false)
;killasgroup=false             ; SIGKILL the UNIX process group (def false)
;user=chrism                   ; setuid to this UNIX account to run the program
;redirect_stderr=true          ; redirect proc stderr to stdout (default false)
;stdout_logfile=/a/path        ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups=10     ; # of stdout logfile backups (default 10)
;stdout_events_enabled=false   ; emit events on stdout writes (default false)
;stderr_logfile=/a/path        ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups        ; # of stderr logfile backups (default 10)
;stderr_events_enabled=false   ; emit events on stderr writes (default false)
;environment=A="1",B="2"       ; process environment additions
;serverurl=AUTO                ; override serverurl computation (childutils)

; The below sample group section shows all possible group values,
; create one or more 'real' group: sections to create "heterogeneous"
; process groups.

;[group:thegroupname]
;programs=progname1,progname2  ; each refers to 'x' in [program:x] definitions

; The [include] section can just contain the "files" setting.  This
; setting can list multiple files (separated by whitespace or
; newlines).  It can also contain wildcards.  The filenames are
; interpreted as relative to this file.  Included files *cannot*
; include files themselves.

;[include]
;files = relative/directory/*.ini

[include]
files = /etc/program.conf

注意:如果你的镜像生成之后,使用 supervisorctl 出现如下错误:
supervisorctl unix ///tmp/supervisor.sock refused connection
请看这篇文章:
supervisorctl unix ///tmp/supervisor.sock refused connection

  • 4
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
要实现一键离线部署 MySQLRedis、Nacos 和 Nginx,你可以使用 Docker Compose 和 Docker 镜像。首先,你需要准备相应的镜像文件并将其加载到 Docker 中。在加载这些镜像之前,你需要确保已经从官方源或其他可信渠道下载了这些镜像。 以下是一个示例的 `docker-compose.yml` 文件,其中包含MySQLRedis、Nacos 和 Nginx 的配置: ```yaml version: '3' services: mysql: build: context: ./mysql dockerfile: Dockerfile restart: always ports: - 3306:3306 environment: - MYSQL_ROOT_PASSWORD=your_password volumes: - ./mysql_data:/var/lib/mysql redis: image: redis:latest restart: always ports: - 6379:6379 nacos: build: context: ./nacos dockerfile: Dockerfile restart: always ports: - 8848:8848 nginx: build: context: ./nginx dockerfile: Dockerfile restart: always ports: - 80:80 ``` 在以上示例中,MySQL、Nacos 和 Nginx 使用了自定义的 Dockerfile 来构建镜像。你需要在相应的目录下创建适当的 Dockerfile,以便构建这些镜像Redis 使用了官方提供的最新版本的镜像MySQL 的配置与之前一样,将容器内的 3306 端口映射到主机的 3306 端口。MySQL 的数据也会被挂载到主机的 `./mysql_data` 目录下。 Nacos 和 Nginx 的构建步骤类似于 MySQL。你需要在 `./nacos` 和 `./nginx` 目录下创建适当的 Dockerfile,并编写相应的构建脚本。 在准备好 Dockerfile 后,你可以使用 `docker-compose up -d` 命令来启动这些容器。使用 `-d` 参数可以在后台运行容器。 一旦容器启动成功,你就可以通过相应的端口访问 MySQLRedis、Nacos 和 Nginx。例如,使用 `localhost:3306` 访问 MySQL,`localhost:6379` 访问 Redis,`localhost:8848` 访问 Nacos,`localhost:80` 访问 Nginx。 希望这对你有帮助!如果还有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值