Building an Docker Image: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
(Die Seite wurde neu angelegt: „=Workdir= *cd /root/apache =Dockerfile= *cat Dockerfile <pre> #Baseimage ubuntu 18:04 FROM ubuntu:18.04 #we are the maintainer MAINTAINER technik@xinux.de #on…“)
 
 
(3 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 19: Zeile 19:
 
CMD ["bash", "/start.sh"]
 
CMD ["bash", "/start.sh"]
 
</pre>
 
</pre>
 +
=our start script=
 +
when we initiate the container and mount the volumes manually, this directories cover the original ones in the container.
 +
 +
so they are empty. in this start script, we copy the file structure that we need to start our demon to the right directories.
 +
*cat start.sh
 +
<pre>
 +
#!/bin/bash
 +
if ! test -f /var/www/html/index.html
 +
then
 +
cp -ar /tmp/html/* /var/www/html/
 +
fi 
 +
if ! test -f /etc/apache2/apache2.conf
 +
then
 +
cp -ar /tmp/apache2/* /etc/apache2/
 +
fi
 +
/usr/sbin/apachectl -D FOREGROUND
 +
</pre>
 +
=building the image=
 +
*docker build -t im-apache .

Aktuelle Version vom 8. Oktober 2019, 13:11 Uhr

Workdir

  • cd /root/apache

Dockerfile

  • cat Dockerfile
#Baseimage ubuntu 18:04
FROM ubuntu:18.04
#we are the maintainer 
MAINTAINER technik@xinux.de
#only run at built
RUN  apt-get update && apt-get install -y apache2  && apt-get clean
RUN  cp -ar /etc/apache2 /tmp
RUN  cp -ar /var/www/html /tmp
COPY start.sh /
#exposed ports
EXPOSE 80
EXPOSE 443
#command that execute in the container 
CMD ["bash", "/start.sh"]

our start script

when we initiate the container and mount the volumes manually, this directories cover the original ones in the container.

so they are empty. in this start script, we copy the file structure that we need to start our demon to the right directories.

  • cat start.sh
#!/bin/bash
if ! test -f /var/www/html/index.html
then 
cp -ar /tmp/html/* /var/www/html/
fi  
if ! test -f /etc/apache2/apache2.conf
then 
cp -ar /tmp/apache2/* /etc/apache2/
fi 
/usr/sbin/apachectl -D FOREGROUND

building the image

  • docker build -t im-apache .