Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tools:docker [2022/06/29 12:45] – [Miscellaneous] darrontools:docker [2022/07/17 16:11] (current) – [Resources] darron
Line 3: Line 3:
 Docker is similar to [[:tools:lxc|LXC]], however it is geared to running a single Docker is similar to [[:tools:lxc|LXC]], however it is geared to running a single
 application within its jailed system rather than being a lightweight application within its jailed system rather than being a lightweight
-VM. It's like having a chroot management system enhanced with networking.+VM. It's like having a chroot management system enhanced with networking. One side 
 +effect of not having an init process is zombie processes can accumulate in the container. Docker is also dependant on the overlay2 file system which is relatively slow.
  
 Docker has a lot of pre-built applications, and due to this the docker ecosystem Docker has a lot of pre-built applications, and due to this the docker ecosystem
Line 231: Line 232:
 </code> </code>
  
-===WordPress===+===WordPress development=== 
 + 
 +This is the process I used to develop a WordPress docker container. Following this is 
 +the method using a Dockerfile which automates the process once it is known. Some differences 
 +are also found in the application of the container during development.
  
 ==Proxy== ==Proxy==
Line 265: Line 270:
 apk update apk update
 apk upgrade apk upgrade
-apk add php8 php8-apache2 php8-mysqli php8-mysqlnd php8-opcache php8-cli php8-ctype php8-iconv php8-session php8-simplexml php8-tokenizer php8-openssl php8-phar php8-curl php8-dom php8-exif php8-fileinfo php8-pecl-imagick php8-mbstring php8-zip php8-gb php-intl+apk add php8 php8-apache2 php8-mysqli php8-mysqlnd php8-opcache php8-cli php8-ctype php8-iconv php8-session php8-simplexml php8-tokenizer php8-openssl php8-phar php8-curl php8-dom php8-exif php8-fileinfo php8-pecl-imagick php8-mbstring php8-zip php8-gd php-intl
 ln -sf /usr/bin/php8 /usr/local/bin/php ln -sf /usr/bin/php8 /usr/local/bin/php
 exit exit
Line 328: Line 333:
 <code> <code>
 docker exec -it alpine_linux sh docker exec -it alpine_linux sh
-cd /var/www/localhost +cd /var/www/localhost/htdocs 
-wget "https://wordpress.org/latest.zip" -d htdocs+wget "https://wordpress.org/latest.zip"
 unzip latest.zip unzip latest.zip
-chown -R apache:apache htdocs/wordpress+rm latest.zip 
 +chown -R apache:apache wordpress
 exit exit
 </code> </code>
Line 351: Line 357:
  
 define('FS_METHOD','direct'); define('FS_METHOD','direct');
 +</code>
 +
 +===WordPress Dockerfile===
 +
 +A docker file can be used to automate the building of an image after one
 +has been developed.
 +
 +Here is a simple Makefile just used to contain various rules.
 +
 +<code>
 +clean:
 +        rm -f *~
 +
 +build:
 +        docker build --no-cache -t alpine_wp .
 +
 +run:
 +        docker run -d -t --net vlan --ip 10.44.0.11 --name wp-dev alpine_wp
 +
 +test:
 +        curl -v http://10.44.0.11/
 +
 +stop:
 +        docker stop wp-dev
 +
 +rm:
 +        docker rm -f wp-dev
 +        docker image rm -f alpine_wp
 +</code>
 +
 +The Makefile uses a Dockerfile to make the build, as follows:
 +
 +<code>
 +# LATEST WORDPRESS ON ALPINE LINUX
 +FROM alpine:latest
 +# INSTALL APACHE2/PHP8
 +RUN apk --no-cache update && apk --no-cache upgrade && apk --no-cache add php8 php8-apache2 php8-mysqli php8-mysqlnd php8-opcache php8-cli php8-ctype php8-iconv php8-session php8-simplexml php8-tokenizer php8-openssl php8-phar php8-curl php8-dom php8-exif php8-fileinfo php8-pecl-imagick php8-mbstring php8-zip php8-gd php-intl && ln -sf /usr/bin/php8 /usr/local/bin/php
 +# INSTALL WORDPRESS
 +WORKDIR /var/www/localhost/htdocs
 +RUN wget -q "https://wordpress.org/latest.zip" && unzip -q latest.zip && rm latest.zip && chown -R apache:apache wordpress && rm -f index.html && echo "<?php header('Location: /wordpress/')?>" > index.php
 +# START HTTPD
 +EXPOSE 80
 +ENTRYPOINT /usr/sbin/httpd -DFOREGROUND
 </code> </code>
  
Line 422: Line 471:
 ==Clone== ==Clone==
  
-First stop the container to commit any changes.+__First stop the container to commit any changes__ 
 + 
 +The commit creates a tagged version of the container which 
 +has any changes made since installation.
  
 <code> <code>
 +docker stop alpine_lunux
 docker commit alpine_linux wordpress:v1 docker commit alpine_linux wordpress:v1
 </code> </code>
  
-Container can be restarted now.+__Container can be restarted now__
  
-Save the docker image.+<code> 
 +docker start alpine_linux 
 +</code> 
 + 
 +__Save the docker container as an image__ 
 + 
 +This saves the container at the specified commit tag for import 
 +elsewhere.
  
 <code> <code>
Line 436: Line 496:
 </code> </code>
  
-Container clone can now be used elsewhere.+Container image can now be used elsewhere.
 ===Resources=== ===Resources===
  
 [[https://docs.docker.com/get-started/|Docker HOWTO]] [[https://docs.docker.com/get-started/|Docker HOWTO]]
 +
 +[[https://docs.docker.com/develop/develop-images/dockerfile_best-practices/|Dockerfile Tips]]