Dockerfile示例
可以使用systemctl命令的镜像
Dockerfile
shell
vim Dockerfile
FROM centos:7
ENV container docker
RUN yum -y swap -- remove fakesystemd -- install systemd systemd-libs
RUN yum -y update; yum clean all; \
(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"]
基于centos7创建mysql镜像
Dockerfile
FROM centos:7
RUN yum install -y https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm && \
yum -y install yum-utils && \
yum-config-manager --disable mysql80-community && \
yum-config-manager --enable mysql57-community && \
yum -y groupinstall "Development Tools" && \
yum -y install mysql-community-server
ADD ./mysql.sh /
CMD [ "sh","/mysql.sh" ]
mysql.sh
mysqld --initialize #mysql初始化命令
pass=$(grep -o 'root@localhost.*' /var/log/mysqld.log | awk 'END{print $NF}')
mysqld --user=root & #root用户启动mysql
sleep 10
mysqladmin -p"${pass}" password "${MYSQL_ROOT_PASSWORD}"
tail -f /var/log/mysqld.log