Skip to content

Instantly share code, notes, and snippets.

@fliedonion
Last active November 29, 2020 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fliedonion/ee9ba6b60a0d6192b8133b192bcf2256 to your computer and use it in GitHub Desktop.
Save fliedonion/ee9ba6b60a0d6192b8133b192bcf2256 to your computer and use it in GitHub Desktop.
try to shrink centos container image by jun-app.

以下で紹介されていたコンテナのサイズが小さくなればいいなとためしてみた。

https://jun-app.com/laravel-on-docker/

単純にRUNを結合した飲み。 うちだとsystemdなコンテナは使えないので (Volumeのマウント的にも)、動作確認はしていない。

インストールパッケージを参考にさせてもらって別のベースイメージでつくってみようかな(独り言)

結果から:

% docker images | grep jun | sort -k2
jun-app/centos8_apache                          1.0                   9c36c5ccbabe        26 minutes ago      939MB
jun-app/centos8_apache                          1.1                   94f6a71953fd        17 minutes ago      808MB
jun-app/centos8_apache                          1.2                   a70f4b287eba        8 minutes ago       764MB

ビルドについて: ブログには記載がなかったのと、まだ動作もさせてないので httpd.conf, php.ini は 空のファイルを用意した。

% ls   
Dockerfile	httpd.conf	php.ini
% docker build --no-cache=true -t jun-app/centos8_apache:1.2 .
  • 1.0がブログそのまま。
  • 1.2がこのGISTに付属の Dockerfile
  • 1.11.2の違いは最後の rm -rf /var/cache/yum/* の有無 (1.1 rm 無 / 1.2 rm 有)
FROM centos:8
ENV container docker
RUN /bin/cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime && \
(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/*; \
yum install -y epel-release && \
rpm -ivh http://ftp.riken.jp/Linux/remi/enterprise/remi-release-8.rpm && \
yum -y update && \
yum -y install httpd && \
yum -y install \
php74-php php74-php-devel \
php74-php-mbstring \
php74-php-mysqli \
php74-php-gd \
php74-php-opcache php74-php-xml \
php74-php-pear php74-php-pecl-zip \
php74-php-pecl-imagick php74-php-pecl-imagick-devel && \
yum clean all && \
ln /usr/bin/php74 /usr/bin/php && \
chown -R apache:apache /var/www/html && \
systemctl enable php74-php-fpm && systemctl enable httpd && \
dnf -y module enable nodejs:12 && \
dnf -y install nodejs && \
dnf clean all && \
rm -rf /var/cache/yum/*;
COPY ./httpd.conf /etc/httpd/conf/httpd.conf
COPY ./php.ini /etc/opt/remi/php74/php.ini
VOLUME [ "/var/www/html" ]
VOLUME [ "/sys/fs/cgroup" ]
CMD ["/usr/sbin/init"]
EXPOSE 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment