使用Docker快速搭建生产环境

Docker安装

CentOS 6.5:

yum install -y docker-io
service docker start

下载镜像

配置使用国内镜像:修改Docker配置文件/etc/default/docker如下

DOCKER_OPTS="--registry-mirror=http://aad0405c.m.daocloud.io"
docker pull redis:3.2.12
docker pull mysql:5.6.41
docker pull centos:7.5.1804
docker pull webcenter/activemq:5.14.3

重新启动,service docker restart


启动

dockerui

用于图形化远程管理镜像和容器,启动后浏览器访问9000端口。

docker run --name='dockerui' -d \
-e="/docker.sock" \
-v /var/run/docker.sock:/docker.sock \
-p 9000:9000 \
abh1nav/dockerui:latest


ActiveMQ

docker run --name='activemq' -d \
-e 'ACTIVEMQ_CONFIG_NAME=amqp-srv1' \
-e 'ACTIVEMQ_CONFIG_DEFAULTACCOUNT=false' \
-e 'ACTIVEMQ_ADMIN_LOGIN=admin' -e 'ACTIVEMQ_ADMIN_PASSWORD=admin' \
-e 'ACTIVEMQ_CONFIG_MINMEMORY=512' -e  'ACTIVEMQ_CONFIG_MAXMEMORY=2048' \
-e 'ACTIVEMQ_CONFIG_SCHEDULERENABLED=true' \
-v /opt/docker-runtime/activemq/data:/data \
-v /opt/docker-runtime/activemq/log:/var/log/activemq \
-p 8161:8161 \
-p 61616:61616 \
-p 61613:61613 \
webcenter/activemq:5.14.3


Redis

docker run --name='redis' -d\
-v /opt/docker-runtime/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf \
-v /opt/docker-runtime/redis/data:/var/lib/redis \
-v /opt/docker-runtime/redis/log:/var/log/redis \
-p 6379:6379 \
redis:3.2.12 \
/usr/local/bin/redis-server /usr/local/etc/redis/redis.conf --appendonly yes


配置文件redis.conf复制到/opt/docker-runtime/redis/conf/目录下

MySQL

docker run --name='mysql' -d \
-e MYSQL_ROOT_PASSWORD=Admin123 \
-e MYSQL_DATABASE=caict \
-e MYSQL_USER=user \
-e MYSQL_PASSWORD=User123 \
-v /opt/docker-runtime/mysql/conf/my.cnf:/etc/mysql/my.cnf \
-v /opt/docker-runtime/mysql/data:/var/lib/mysql \
-v /opt/docker-runtime/mysql/log:/var/log/mysql \
-p 3706:3306 \
mysql:5.6.41


配置文件my.cnf复制到/opt/docker-runtime/mysql/conf/目录下

导入脚本:

docker exec -i mysql mysql -uroot -p"Admin123" caict

Tomcat
制作

  • 准备:

下载 apache-tomcat-7.0.90.tar.gz 和 jre-7u67-linux-x64.tar.gz,并解压缩

mkdir tomcat

cd tomcat

tar zxvf apache-tomcat-7.0.90.tar.gz 

tar zxvf  jre-7u67-linux-x64.tar.gz
  • 编制Dockerfile
FROM centos:7.5.1804
#创建目录
RUN mkdir -p /opt
#把当前目录下的jdk文件夹添加到镜像
ADD apache-tomcat-7.0.90 /opt/apache-tomcat-7.0.90
ADD jre1.7.0_67 /opt/jre1.7.0_67
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ENV LC_ALL zh_CN.utf8
ENV JAVA_HOME /opt/jre1.7.0_67
ENV CATALINA_HOME /opt/apache-tomcat-7.0.90
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin
#暴露8080端口
EXPOSE 8080
#启动时运行tomcat
CMD ["/opt/apache-tomcat-7.0.90/bin/catalina.sh","run"]
  • 执行制作
docker build -t sbr/tomcat7:1.1 .

启动

docker run -it --name='tomat' -d  \
-v /opt/docker-runtime/tomcat/webapps:/opt/apache-tomcat-7.0.90/webapps \
-v /opt/docker-runtime/tomcat/log:/opt/apache-tomcat-7.0.90/logs \
-v /opt/docker-runtime/tomcat/work:/opt/apache-tomcat-7.0.90/work \
-v /opt/docker-runtime/tomcat/temp:/opt/apache-tomcat-7.0.90/temp \
-p 80:8080 \
sbr/tomcat7:1.1

把war文件复制到/opt/docker-runtime/tomcat/webapps目录下。

你可能感兴趣的:(Docker)