从零构建 docker镜像 mysql+tomcat+redis

第一步:写好如下Dockerfile 开启systemd,否则使用 systemctl 命令会报 Failed to get D-Bus connection: Operation not permitted

FROM centos
MAINTAINER [email protected]
ENV container docker
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \
systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ "/sys/fs/cgroup" ]
CMD ["/usr/sbin/init"]

注意,在空目录创建操作,不然会报错 

docker build -t mycentos .

开始构建自己需要的镜像。java和tomcat从官方下载的,放在和Dockerfile通目录下。

FROM centos
MAINTAINER [email protected]
ENV container docker
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \
systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ "/sys/fs/cgroup" ]
CMD ["/usr/sbin/init"]
RUN yum install -y http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm  \
&& yum -y install mysql-community-server \
&& yum install -y http://rpms.famillecollet.com/enterprise/remi-release-7.rpm \
&& yum --enablerepo=remi install redis \
ADD jdk-8u201-linux-x64.rpm jdk-8u201-linux-x64.rpm
RUN yum install jdk-8u201-linux-x64.rpm
ADD apache-tomcat-8.5.38.tar.gz /usr/local/tomcat 
RUN rm -rf /usr/local/tomcat/webapps/*  \
&& mkdir -p /usr/local/tomcat/webapps/ROOT \
&& /usr/local/tomcat/bin/startup.sh
EXPOSE 8080
EXPOSE 6379
EXPOSE 3306
CMD ["/bin/bash"]

 

你可能感兴趣的:(docker)