diff --git a/README.md b/README.md index da74e0c..71a19bb 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ # Things You Can Learn From This * How to build a `docker` image from a "dockerfile" +8 How to tag `docker` images * How to use `ansible` to create and destroy a `docker` network * How to use `ansible` to create, restart, and destroy `docker` servers * How host and `ssh` keys are managed on a `docker` instance diff --git a/ansible/inventories/group_vars/all b/ansible/inventories/group_vars/all index c68dfce..c977965 100644 --- a/ansible/inventories/group_vars/all +++ b/ansible/inventories/group_vars/all @@ -1,9 +1,5 @@ # Default credentials - can be overriden by environment-specific definitions -# Docker Variables - -dockersand_registry: "dockersand:5000" - # Sandbox Default Startup Variables # These have to be here, and not in the dockersan variable file, because @@ -11,6 +7,6 @@ # against the sandbox inventory. dockersand_subnet: "192.168.11.0/24" -dockersand_image: "dockersand-debian" +dockersand_image: "dockersand-centos7" dockersand_start: "1" dockersand_end: "10" diff --git a/ansible/playbooks/dockersand/dockersand_build.yml b/ansible/playbooks/dockersand/dockersand_build.yml index 35754c6..066154f 100644 --- a/ansible/playbooks/dockersand/dockersand_build.yml +++ b/ansible/playbooks/dockersand/dockersand_build.yml @@ -8,9 +8,9 @@ register: domainname - name: Create docker sandbox containers - command: docker run -dh "dock{{ item }}.{{ domainname.stdout }}" \ + command: docker run -dh "dockersand{{ item }}.{{ domainname.stdout }}" \ --name "dockersand{{ item }}" \ --net=dockersand-net \ --volume=/shared:/shared \ - "{{ dockersand_registry }}/{{ dockersand_image }}" + "{{ dockersand_image }}" with_sequence: start="{{ dockersand_start }}" end="{{ dockersand_end }}" diff --git a/dockerfiles/build-img.sh b/dockerfiles/build-img.sh index 79dbf31..e2758bc 100755 --- a/dockerfiles/build-img.sh +++ b/dockerfiles/build-img.sh @@ -1,8 +1,6 @@ #!/bin/sh # Build specified docker image and tag with today's date -REGISTRY="dockersand:5000" - # Setup correct permissions for ssh files chmod 600 common/keys/*key chmod 700 common/.ssh @@ -10,8 +8,8 @@ chmod 644 common/.ssh/*.pub # Tags -LATEST=${REGISTRY}/${1}:latest -DATED=${REGISTRY}/${1}:`date +%Y%m%d` +LATEST=${1}:latest +DATED=${1}:`date +%Y%m%d` # Get rid of older images docker rmi ${DATED} ${LATEST} diff --git a/dockerfiles/dockersand-centos7/dockersand-centos7.dockerfile b/dockerfiles/dockersand-centos7/dockersand-centos7.dockerfile new file mode 100644 index 0000000..5471cac --- /dev/null +++ b/dockerfiles/dockersand-centos7/dockersand-centos7.dockerfile @@ -0,0 +1,45 @@ +# Dockerfile For CentOS7 Docker Sandbox + +FROM centos:7 +MAINTAINER tundra@tundraware.com + +# Update OS and install software + +RUN yum -y upgrade +RUN yum -y install epel-release +RUN yum -y install bind-utils bzip2 dos2unix emacs-nox git htop joe lsof nc nload \ + net-tools openssh-server psmisc python2-pip python3 python3-pip \ + screen socat sudo the_silver_searcher tree which wget zip +RUN yum clean all + +# Enable sshd with same keys each time +ADD common/keys/ /etc/ssh/ +RUN mkdir /var/run/sshd + +# Setup and configure user: root + +ADD common/.ssh/ /root/.ssh/ +RUN chmod 700 /root +RUN mkdir /root/tmp +RUN chown -R root:root /root +RUN chmod 700 /root/.ssh +RUN chmod 600 /root/.ssh/authorized_keys +RUN chmod 600 /root/.ssh/*rsa + +# Setup and configure user: test + +RUN useradd -m -p snLOSb4wiVD0k -u 1000 -s /bin/bash test +ADD common/.ssh/ /home/test/.ssh/ +RUN mkdir /home/test/tmp +RUN chown -R test:test /home/test +RUN chmod 700 /home/test/.ssh +RUN chmod 600 /home/test/.ssh/authorized_keys +RUN chmod 600 /home/test/.ssh/*rsa + +# Configure sudo + +RUN echo "test ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers + +# Start sshd on instantiation + +ENTRYPOINT /usr/sbin/sshd && sleep inf diff --git a/dockerfiles/dockersand-debian/dockersand-debian.dockerfile b/dockerfiles/dockersand-debian/dockersand-debian.dockerfile deleted file mode 100644 index 5c9b48d..0000000 --- a/dockerfiles/dockersand-debian/dockersand-debian.dockerfile +++ /dev/null @@ -1,53 +0,0 @@ -# Dockerfile Docker Sandbox Debian Image - -FROM debian -MAINTAINER tundra@tundraware.com - -# Update OS and install software - -RUN apt-get -y update -RUN apt-get -y install apt-utils -RUN apt-get -y dist-upgrade -RUN apt-get -y upgrade -RUN apt-get -y install bzip2 curl dnsutils dos2unix emacs-nox ethtool git \ - htop joe less lsof netcat net-tools nfs-common \ - nload openssh-server psmisc python-pip rsync screen \ - socat sudo silversearcher-ag tree unzip vim whois \ - wget zip - -# Add sandboxes to hosts file - -CMD cat common/etc/dockersand.hosts >> /etc/hosts - -# Enable sshd with same keys each time -ADD common/keys/ /etc/ssh/ -RUN mkdir /var/run/sshd - -# Setup and configure user: root - -ADD common/.ssh/ /root/.ssh/ -RUN chmod 700 /root -RUN mkdir /root/tmp -RUN chown -R root:root /root -RUN chmod 700 /root/.ssh -RUN chmod 600 /root/.ssh/authorized_keys -RUN chmod 600 /root/.ssh/*rsa - -# Setup and configure user: test - -RUN useradd -m -p snLOSb4wiVD0k -u 1000 -s /bin/bash test -ADD common/.ssh/ /home/test/.ssh/ -RUN chmod 700 /home/test -RUN mkdir /home/test/tmp -RUN chown -R test:test /home/test -RUN chmod 700 /home/test/.ssh -RUN chmod 600 /home/test/.ssh/authorized_keys -RUN chmod 600 /home/test/.ssh/*rsa - -# Configure sudo - -RUN echo "test ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers - -# Start sshd on instantiation - -ENTRYPOINT /usr/sbin/sshd && sleep inf