Difference between revisions of "Manual container creation"

From Tech-Wiki
Jump to: navigation, search
(Created page with "Category:Linux If you need to create a custom container image, adding your own packages, create a Dockfile as follows: FROM ulsmith/debian-apache-php LABEL Edwin edwin...")
 
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[Category:Linux]]
 
[[Category:Linux]]
  
If you need to create a custom container image, adding your own packages, create a Dockfile as follows:
+
If you need to create a custom container image, adding your own packages, create a Dockerfile as follows:
  
  FROM ulsmith/debian-apache-php
+
  FROM debian:jessie
  LABEL Edwin edwin@example.com
+
  MAINTAINER Paul Smith <p@ulsmith.net>
 +
LABEL Custom container
 +
WORKDIR /home
 +
WORKDIR project
 
  RUN echo "deb http://ftp.de.debian.org/debian stretch main" >> /etc/apt/sources.list
 
  RUN echo "deb http://ftp.de.debian.org/debian stretch main" >> /etc/apt/sources.list
  RUN apt-get update
+
  RUN apt-get update && \
RUN apt-get install -y python bash
+
    apt-get -yq install \
RUN apt-get clean -y
+
        apache2 \
 +
        php5 \
 +
        libapache2-mod-php5 \
 +
        curl \
 +
        ca-certificates \
 +
        php5-curl \
 +
        php5-json \
 +
        php5-odbc \
 +
        php5-sqlite \
 +
        php5-mysql \
 +
        php5-mcrypt \
 +
        python bash && \
 +
    apt-get clean -y && \
 +
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/cache/apt/archive/*.deb
 +
RUN /usr/sbin/php5enmod mcrypt && a2enmod rewrite && mkdir /bootstrap
 +
ADD site.conf /etc/apache2/sites-available/000-default.conf
 +
ADD start.sh /bootstrap/start.sh
 +
RUN chmod 755 /bootstrap/start.sh && chown -R www-data:www-data /var/www/html
 
  EXPOSE 80
 
  EXPOSE 80
  CMD ["/start.sh"]
+
  VOLUME /etc/apache2/sites-available
 +
ENTRYPOINT ["/bootstrap/start.sh","param1"]
  
 
start.sh
 
start.sh
Line 26: Line 47:
 
         Order allow,deny
 
         Order allow,deny
 
         Allow from All
 
         Allow from All
Require all granted
+
            Require all granted
</Directory>
+
    </Directory>
 
  </VirtualHost>
 
  </VirtualHost>
 
   ServerName localhost
 
   ServerName localhost
Line 33: Line 54:
 
   ServerTokens Prod
 
   ServerTokens Prod
  
The image based on Dockfile file above can be generated by the command below
+
The image based on Dockerfile file above can be generated by the command below
 
  docker image build -t container1 .
 
  docker image build -t container1 .
  
Then you can run this container using the compose file below:
+
You can also run this container using the compose.yaml file below (which will build the image anyway):
version: '2'
+
version: '2'
services:
+
services:
  myproject:
+
  myproject:
    build: ./
+
    build: ./
    container_name: my_project
+
    container_name: webserver
    restart: always
+
    restart: always
    networks:
+
    networks:
      - docker-localhost
+
      - docker-localhost
    ports:
+
    ports:
      - 80:80
+
      - 80:80
networks:
+
    volumes:
  docker-localhost:
+
      - /data/site:/var/www/html
 +
networks:
 +
  docker-localhost:
 +
 
 +
If using the compose.yaml file above, the container can be executed using:
 +
 
 +
docker-compose up -d

Latest revision as of 21:16, 23 April 2020


If you need to create a custom container image, adding your own packages, create a Dockerfile as follows:

FROM debian:jessie
MAINTAINER Paul Smith <[email protected]>
LABEL Custom container
WORKDIR /home
WORKDIR project
RUN echo "deb http://ftp.de.debian.org/debian stretch main" >> /etc/apt/sources.list
RUN apt-get update && \
   apt-get -yq install \
       apache2 \
       php5 \
       libapache2-mod-php5 \
       curl \
       ca-certificates \
       php5-curl \
       php5-json \
       php5-odbc \
       php5-sqlite \
       php5-mysql \
       php5-mcrypt \
       python bash && \
   apt-get clean -y && \
   rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/cache/apt/archive/*.deb
RUN /usr/sbin/php5enmod mcrypt && a2enmod rewrite && mkdir /bootstrap
ADD site.conf /etc/apache2/sites-available/000-default.conf
ADD start.sh /bootstrap/start.sh
RUN chmod 755 /bootstrap/start.sh && chown -R www-data:www-data /var/www/html
EXPOSE 80
VOLUME /etc/apache2/sites-available
ENTRYPOINT ["/bootstrap/start.sh","param1"]

start.sh

#!/bin/bash
source /etc/apache2/envvars
exec apache2 -D FOREGROUND

site.conf

<VirtualHost *:80>
   ServerAdmin webmaster@localhost
   DocumentRoot /var/www/html
   <Directory /var/www/html>
       Options FollowSymLinks
       AllowOverride All
       Order allow,deny
       Allow from All
           Require all granted
   </Directory>
</VirtualHost>
 ServerName localhost
 ServerSignature Off
 ServerTokens Prod

The image based on Dockerfile file above can be generated by the command below

docker image build -t container1 .

You can also run this container using the compose.yaml file below (which will build the image anyway):

version: '2'
services:
  myproject:
    build: ./
    container_name: webserver
    restart: always
    networks:
      - docker-localhost
    ports:
      - 80:80
    volumes:
      - /data/site:/var/www/html
networks:
  docker-localhost:

If using the compose.yaml file above, the container can be executed using:

docker-compose up -d