63 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Docker
		
	
	
	
	
	
			
		
		
	
	
			63 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Docker
		
	
	
	
	
	
# Copyright 2019 Mikhail Klementev. All rights reserved.
 | 
						|
# Use of this source code is governed by a AGPLv3 license
 | 
						|
# (or later) that can be found in the LICENSE file.
 | 
						|
#
 | 
						|
# Usage:
 | 
						|
#
 | 
						|
#     $ docker build -t gen-centos7-image .
 | 
						|
#     $ docker run --privileged -v $(pwd):/shared -t gen-centos7-image
 | 
						|
#
 | 
						|
# out_of_tree_centos_7.img will be created in current directory.
 | 
						|
# You can change $(pwd) to different directory to use different destination
 | 
						|
# for image.
 | 
						|
#
 | 
						|
FROM centos:7
 | 
						|
 | 
						|
RUN sed -i 's/enabled=1/enabled=0/' /etc/yum.repos.d/* || true
 | 
						|
RUN sed -i 's/name/enabled=0\nname/' /etc/yum.repos.d/* || true
 | 
						|
RUN echo -e '[7.9.2009-os]\nbaseurl=https://vault.centos.org/7.9.2009/os/$basearch/\ngpgcheck=0' >> /etc/yum.repos.d/oot.repo
 | 
						|
RUN echo -e '[7.9.2009-updates]\nbaseurl=https://vault.centos.org/7.9.2009/updates/$basearch/\ngpgcheck=0' >> /etc/yum.repos.d/oot.repo
 | 
						|
 | 
						|
RUN yum -y update
 | 
						|
RUN yum -y groupinstall "Development Tools"
 | 
						|
RUN yum -y install qemu-img e2fsprogs
 | 
						|
 | 
						|
ENV TMPDIR=/tmp/centos
 | 
						|
 | 
						|
RUN yum --installroot=$TMPDIR \
 | 
						|
        --releasever=7 \
 | 
						|
        -y groupinstall Base
 | 
						|
 | 
						|
RUN rm $TMPDIR/etc/yum.repos.d/*
 | 
						|
RUN cp /etc/yum.repos.d/* $TMPDIR/etc/yum.repos.d/
 | 
						|
 | 
						|
RUN yum --installroot=$TMPDIR \
 | 
						|
        --releasever=7 \
 | 
						|
        -y install openssh-server openssh-clients
 | 
						|
 | 
						|
RUN chroot $TMPDIR /bin/sh -c 'useradd -m user'
 | 
						|
RUN sed -i 's/root:\*:/root::/' $TMPDIR/etc/shadow
 | 
						|
RUN sed -i 's/user:!!:/user::/' $TMPDIR/etc/shadow
 | 
						|
RUN sed -i '/PermitEmptyPasswords/d' $TMPDIR/etc/ssh/sshd_config
 | 
						|
RUN echo PermitEmptyPasswords yes >> $TMPDIR/etc/ssh/sshd_config
 | 
						|
RUN sed -i '/PermitRootLogin/d' $TMPDIR/etc/ssh/sshd_config
 | 
						|
RUN echo PermitRootLogin yes >> $TMPDIR/etc/ssh/sshd_config
 | 
						|
RUN sed -i '/UseDNS/d' $TMPDIR/etc/ssh/sshd_config
 | 
						|
RUN echo UseDNS no >> $TMPDIR/etc/ssh/sshd_config
 | 
						|
 | 
						|
# network workaround
 | 
						|
RUN chmod +x $TMPDIR/etc/rc.local
 | 
						|
RUN echo 'dhclient' >> $TMPDIR/etc/rc.local
 | 
						|
 | 
						|
ENV IMAGEDIR=/tmp/image
 | 
						|
ENV IMAGE=/shared/out_of_tree_centos_7.img
 | 
						|
 | 
						|
RUN mkdir $IMAGEDIR
 | 
						|
 | 
						|
# Must be executed with --privileged because of /dev/loop
 | 
						|
CMD qemu-img create $IMAGE 2G && \
 | 
						|
	mkfs.ext4 -F $IMAGE && \
 | 
						|
	mount -o loop $IMAGE $IMAGEDIR && \
 | 
						|
	cp -a $TMPDIR/* $IMAGEDIR/ && \
 | 
						|
	umount $IMAGEDIR
 |