Nemo

Nemo

路漫漫其修远兮,吾将上下而求索。

Nemo

Nemo

关注TA

路漫漫其修远兮,吾将上下而求索。

  •  普罗旺斯
  • 负责帅就完事了
  • 写了1,430,174字

最近回复

该文章投稿至Nemo社区   Java  板块 复制链接


Docker: Dockerfile 构建Ubuntu + mysql + redis + jdk8 + maven容器

发布于 2020/09/17 17:13 467浏览 0回复 4,525

最近在整理家里服务器的Docker容器,需要整一个方便使用的容器供后续其他测试项目使用。

于是就有了这个脚本,此处做一下备份。

此处解决的问题如下:

1、中文显示问题。

2、默认时区问题。

集成环境如下:

1、操作系统:Ubuntu 16.04,已替换为阿里源。

2、jdk8。

3、mysql5.7。

4、redis6.0.8。

5、maven3.6.3。

6、nginx。

7、vim。

8、ssh。

9、git。

10、wget。

11、make + gcc。


Dockerfile脚本如下:

FROM ubuntu:16.04

MAINTAINER nemo nemo@link-nemo.com

# 基础环境设置
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
RUN export LANG=C.UTF-8
RUN echo "export LANG=zh_CN.UTF-8" >> /etc/locale.conf RUN echo "export TZ='CST-8'" >> /etc/profile
RUN echo "export TZ='CST-8'" >> /root/.bashrcENV LANG C.UTF-8
ENV LC_ALL zh_CN.UTF-8
# mysql 密码 ENV MYSQL_PASS 123456 # redis 密码 ENV REDIS_PASS 123456

#软件源修改为阿里源
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak
RUN touch /etc/apt/sources.list
RUN echo "deb-src http://archive.ubuntu.com/ubuntu xenial main restricted" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted" >> /etc/apt/sources.list
RUN echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted" >> /etc/apt/sources.list
RUN echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ xenial universe" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse" >> /etc/apt/sources.list
RUN echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse" >> /etc/apt/sources.list
RUN echo "deb http://archive.canonical.com/ubuntu xenial partner" >> /etc/apt/sources.list
RUN echo "deb-src http://archive.canonical.com/ubuntu xenial partner" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted" >> /etc/apt/sources.list
RUN echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse" >> /etc/apt/sources.list

# 常用工具安装
RUN apt update
RUN apt install gcc+ make git nginx wget ssh vim --assume-yes

# 安装maven
RUN wget https://mirrors.bfsu.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
RUN mv apache-maven-3.6.3-bin.tar.gz /usr/src/
RUN tar -xzvf /usr/src/apache-maven-3.6.3-bin.tar.gz -C /opt/
RUN mv /opt/apache-maven-3.6.3 /opt/maven3.6.3
ENV MAVEN_HOME /opt/maven3.6.3
ENV PATH $PATH:$MAVEN_HOME/bin

# 安装redis
RUN wget http://download.redis.io/releases/redis-6.0.8.tar.gz
RUN mv redis-6.0.8.tar.gz /usr/src/
RUN tar -xzvf /usr/src/redis-6.0.8.tar.gz -C /opt/
RUN mv /opt/redis-6.0.8 /opt/redis6.0.8
RUN cd /opt/redis6.0.8/ && make
RUN sed -i 's/protected-mode yes/protected-mode no/g' /opt/redis6.0.8/redis.conf
RUN sed -i 's/daemonize no/daemonize yes/g' /opt/redis6.0.8/redis.conf
RUN echo "requirepass ${REDIS_PASS}" >> /opt/redis6.0.8/redis.conf

#安装jdk
RUN wget https://mirrors.huaweicloud.com/java/jdk/8u202-b08/jdk-8u202-linux-x64.tar.gz
RUN mv jdk-8u202-linux-x64.tar.gz /usr/src/
RUN tar -xzvf /usr/src/jdk-8u202-linux-x64.tar.gz -C /opt/
RUN mv /opt/jdk1.8.0_202 /opt/jdk8
ENV JAVA_HOME /opt/jdk8
ENV PATH $PATH:$JAVA_HOME/bin

# 安装mysql
RUN echo "mysql-server-5.7 mysql-server/root_password password ${MYSQL_PASS}" | debconf-set-selections
RUN echo "mysql-server-5.7 mysql-server/root_password_again password ${MYSQL_PASS}" | debconf-set-selections
RUN apt install -y mysql-server

# 对外只暴露80端口
EXPOSE 80

# 中文支持
RUN apt install language-pack-zh-hans --assume-yes

# 设定启动项目
RUN touch /startup.sh && chmod 777 /startup.sh
ENTRYPOINT nginx && service mysql start && /opt/redis6.0.8/src/redis-server /opt/redis6.0.8/redis.conf && /startup.sh && tail -f /dev/null



后续如需部署新的环境,则只需在docker中build一下此脚本即可:

docker build -t nex:1.0.0 -f Dockerfile .

需要注意的是,建议将Dockerfile文件放到一个空文件夹,在执行上述命令时,也应cd到该目录,不然可能会加载多余的文件,耗费时间。



点赞(1)
点了个评