Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tools:docker [2022/06/29 12:48] – [Miscellaneous] darron | tools:docker [2025/02/09 20:09] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====Docker==== | ====Docker==== | ||
- | Docker is similar to [[: | + | Docker is similar to [[: |
- | application within its jailed system rather than being a lightweight | + | |
- | VM. It's like having a chroot management system enhanced with networking. | + | |
- | Docker has a lot of pre-built applications, | + | This page details |
- | is a security nightmare and cannot really be recommended unless you | + | |
- | skip this and create your own builds from base O/S images such as Alpine Linux. | + | |
- | On this page are demos of using Docker on Linux. One container | + | ===Uninstall=== |
- | is an install of Laravel and another is Alpine Linux. The installation | + | |
- | of Laravel should demonstrate the security issues when using pre-built docker | + | |
- | images. | + | |
- | Alpine Linux is further configured for PHP8, composer and Symfony. This | + | Debian' |
- | is not for production, just for development and not fully configured here, yet. | + | |
- | + | ||
- | Later a build is investigated containing WordPress using Alpine Linux | + | |
- | and accessed via a proxy with nginx. | + | |
- | + | ||
- | ===Environment=== | + | |
- | + | ||
- | VirtualBox virtual machine manager or Xen virtual machine. | + | |
- | + | ||
- | ===Operating System=== | + | |
- | + | ||
- | Devuan Chimaera on VirtualBox or Debian Bullseye on Xen. | + | |
- | + | ||
- | ===Docker=== | + | |
- | + | ||
- | ==Install== | + | |
< | < | ||
- | apt-get | + | apt-get |
- | apt-get install | + | |
- | apt-get install | + | |
</ | </ | ||
- | ==User== | + | Clean up and reboot if an old version was removed. |
- | + | ||
- | Add your login user to the docker group with vigr and vigr -s and relog. | + | |
- | + | ||
- | ==Run== | + | |
< | < | ||
- | / | + | apt-get autoremove |
+ | reboot | ||
</ | </ | ||
- | ===Laravel=== | + | ===Install=== |
- | < | + | [[https://docs.docker.com/engine/install/debian/# |
- | wget "https://laravel.build/ | + | |
- | sh ./example-app.sh | + | |
- | cd example-app | + | |
- | ./vendor/bin/sail up | + | |
- | </ | + | |
- | + | ||
- | ===Alpine Linux=== | + | |
- | + | ||
- | Alpine Linux is a lightweight Linux ideal for running inside a container. | + | |
- | + | ||
- | ==Install== | + | |
- | + | ||
- | Fetch the image and create the container. | + | |
< | < | ||
- | docker pull alpine: | + | sudo apt-get update |
- | docker create | + | sudo apt-get install ca-certificates curl |
- | </code> | + | sudo install |
+ | sudo curl -fsSL https:// | ||
+ | sudo chmod a+r /etc/ | ||
- | ==Start== | + | echo \ |
+ | "deb [arch=$(dpkg --print-architecture) signed-by=/ | ||
+ | $(. / | ||
+ | sudo tee / | ||
- | Start Alpine Linux. | + | sudo apt-get update |
- | + | sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin | |
- | < | + | |
- | docker | + | |
</ | </ | ||
- | ==Shell== | + | ===Setup=== |
- | Connect to a shell within Alpine Linux. | + | [[https:// |
< | < | ||
- | docker | + | sudo groupadd |
+ | sudo usermod | ||
</ | </ | ||
- | ==Stop== | + | ===Reboot=== |
- | + | ||
- | Stop Alpine Linux | + | |
< | < | ||
- | docker stop alpine_linux | + | reboot |
</ | </ | ||
- | ==Delete== | + | ===Test=== |
- | + | ||
- | How do delete Alpine Linux if necessary. | + | |
< | < | ||
- | docker | + | docker |
+ | Docker version 27.5.1, build 9f9e405 | ||
</ | </ | ||
- | |||
- | ===PHP8=== | ||
- | |||
- | ==Install== | ||
< | < | ||
- | docker | + | docker |
- | apk update | + | Docker Compose version v2.32.4 |
- | apk upgrade | + | |
- | apk add php8 php8-fpm php8-opcache php8-cli php8-ctype php8-iconv php8-session php8-simplexml php8-tokenizer php8-openssl php8-phar | + | |
- | ln -sf / | + | |
- | exit | + | |
</ | </ | ||
- | |||
- | ===Composer=== | ||
- | |||
- | ==Git== | ||
< | < | ||
- | docker exec -it alpine_linux apk add git | + | ip addr show docker0 |
+ | 4: docker0: <NO-CARRIER, | ||
+ | link/ether 02: | ||
+ | inet 172.17.0.1/ | ||
+ | | ||
</ | </ | ||
- | |||
- | ==Install== | ||
- | |||
- | Visit the composer downloads page to find the composer installer script. | ||
- | |||
- | [[https:// | ||
- | |||
- | Save the script as composer-installer.sh | ||
< | < | ||
- | php -r " | + | docker run hello-world |
- | php -r "if (hash_file(' | + | |
- | php composer-setup.php | + | |
- | php -r " | + | |
- | </ | + | |
- | Run the saved script. | + | Hello from Docker! |
+ | This message shows that your installation appears to be working correctly. | ||
- | < | + | To generate this message, Docker took the following steps: |
- | sh composer-installer.sh | + | 1. The Docker client contacted the Docker daemon. |
- | Installer verified | + | 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. |
- | All settings correct for using Composer | + | |
- | Downloading... | + | 3. The Docker daemon created a new container from that image which runs the |
+ | | ||
+ | 4. The Docker daemon streamed that output to the Docker client, which sent it | ||
+ | to your terminal. | ||
- | Composer (version 2.3.5) successfully installed to: / | + | To try something more ambitious, you can run an Ubuntu container with: |
- | Use it: php composer.phar | + | $ docker run -it ubuntu bash |
- | </ | + | |
- | Move the blob into your path. | + | Share images, automate workflows, and more with a free Docker ID: |
+ | | ||
- | < | + | For more examples and ideas, visit: |
- | mv composer.phar | + | https://docs.docker.com/get-started/ |
</ | </ | ||
- | ===Symfony=== | ||
- | |||
- | ==Install== | ||
- | |||
- | Fetch the symfony blob. | ||
- | |||
- | < | ||
- | wget " | ||
- | tar zxvf symfony-cli_linux_amd64.tar.gz | ||
- | </ | ||
- | |||
- | Move the blob into your path. | ||
- | |||
- | < | ||
- | mv symfony / | ||
- | </ | ||
- | |||
- | ==Application== | ||
- | |||
- | Create a symfony application. | ||
- | |||
- | < | ||
- | symfony new --webapp my_project | ||
- | </ | ||
- | |||
- | ===Fixed IP address=== | ||
- | |||
- | ==Bridge== | ||
- | |||
- | Create a network bridge using docker. | ||
- | |||
- | < | ||
- | docker network create --subnet=10.44.0.0/ | ||
- | </ | ||
- | |||
- | ==Run== | ||
- | |||
- | Create and run the container. The option d starts the container in the background and t assigns a pseudo tty. | ||
- | |||
- | < | ||
- | docker pull alpine: | ||
- | docker run -d -t --net vlan --ip 10.44.0.10 --name alpine_linux alpine | ||
- | </ | ||
- | |||
- | ==Command== | ||
- | |||
- | Run a command in the container | ||
- | |||
- | < | ||
- | docker exec -it alpine_linux / | ||
- | eth0 Link encap: | ||
- | inet addr: | ||
- | UP BROADCAST RUNNING MULTICAST | ||
- | RX packets:10 errors:0 dropped:0 overruns:0 frame:0 | ||
- | TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 | ||
- | collisions: | ||
- | RX bytes:876 (876.0 B) TX bytes:0 (0.0 B) | ||
- | </ | ||
- | |||
- | ==Stop== | ||
- | |||
- | Stop container | ||
- | |||
- | < | ||
- | docker stop alpine_linux | ||
- | </ | ||
- | |||
- | ==Restart== | ||
- | |||
- | Restart container | ||
- | |||
- | < | ||
- | docker start alpine_linux | ||
- | </ | ||
- | |||
- | ===WordPress=== | ||
- | |||
- | ==Proxy== | ||
- | |||
- | Install nginx in the main host. | ||
- | |||
- | < | ||
- | apt install nginx-full php php-cli php-fpm | ||
- | </ | ||
- | |||
- | Use proxy_pass to direct a https URL to the container. | ||
- | |||
- | Eg. | ||
- | < | ||
- | location / { | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | } | ||
- | </ | ||
- | |||
- | ==Apache2== | ||
- | |||
- | Install apache2 in the container. | ||
- | |||
- | __Install__ | ||
- | < | ||
- | docker exec -it alpine_linux sh | ||
- | apk update | ||
- | 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 | ||
- | ln -sf / | ||
- | exit | ||
- | </ | ||
- | |||
- | __Config__ | ||
- | |||
- | At the least edit the Listen and ServerName directives in / | ||
- | |||
- | < | ||
- | Listen *:80 | ||
- | ServerName WordPress | ||
- | ServerAdmin root | ||
- | ServerTokens Prod | ||
- | ServerSignature Off | ||
- | </ | ||
- | |||
- | __Logging__ | ||
- | |||
- | Use mod remoteip resolve client ip address. | ||
- | |||
- | __Newer apache2__ | ||
- | < | ||
- | RemoteIPProxyProtocol On | ||
- | RemoteIPProxyProtocolExceptions 127.0.0.1 X.X.X.X/24 | ||
- | RemoteIPHeader X-Forwarded-For | ||
- | RemoteIPTrustedProxy X.X.X.X | ||
- | </ | ||
- | |||
- | __Older apache2__ | ||
- | < | ||
- | RemoteIPHeader X-Real-IP | ||
- | RemoteIPTrustedProxy X.X.X.X | ||
- | LogFormat "%a %l %u %t \" | ||
- | </ | ||
- | |||
- | __Run__ | ||
- | |||
- | Start apache2 in the container. | ||
- | |||
- | < | ||
- | docker exec -it alpine_linux / | ||
- | </ | ||
- | |||
- | To keep this process up, start it from RUNIT or similar in the main docker host. | ||
- | |||
- | __run__ | ||
- | < | ||
- | / | ||
- | exec / | ||
- | </ | ||
- | |||
- | __finish__ | ||
- | < | ||
- | / | ||
- | </ | ||
- | |||
- | ==WordPress== | ||
- | |||
- | Install WordPress in the container. | ||
- | |||
- | < | ||
- | docker exec -it alpine_linux sh | ||
- | cd / | ||
- | wget " | ||
- | unzip latest.zip | ||
- | chown -R apache: | ||
- | exit | ||
- | </ | ||
- | |||
- | The URL will become https:// | ||
- | https:// | ||
- | |||
- | If a MySQL server is not available then MySQL must be started in another | ||
- | container in the same network. | ||
- | |||
- | Add custom config values to support proxy. | ||
- | < | ||
- | define(' | ||
- | // in some setups HTTP_X_FORWARDED_PROTO might contain | ||
- | // a comma-separated list e.g. http,https | ||
- | // so check for https existence | ||
- | if (strpos($_SERVER[' | ||
- | $_SERVER[' | ||
- | |||
- | define(' | ||
- | </ | ||
- | |||
- | |||
- | ===Miscellaneous=== | ||
- | |||
- | ==Copy file== | ||
- | |||
- | < | ||
- | docker cp .vimrc alpine_linux:/ | ||
- | </ | ||
- | |||
- | ==Apache log rotation== | ||
- | |||
- | < | ||
- | #! /bin/sh | ||
- | |||
- | # Apache log rotation. | ||
- | # | ||
- | # Dmb May 1999 - Jun 2022. | ||
- | |||
- | # Alpine Linux: | ||
- | # | ||
- | # apk add apache2-utils webalizer | ||
- | # | ||
- | # 0 1 * * * / | ||
- | |||
- | umask 022 | ||
- | |||
- | LOGDIR="/ | ||
- | WEBLOG=" | ||
- | LOGFILES=" | ||
- | STATDIR=" | ||
- | |||
- | cd $LOGDIR | ||
- | |||
- | for f in $LOGFILES | ||
- | do | ||
- | if test -f $f; then | ||
- | |||
- | test -f $f.6.gz && mv $f.6.gz $f.7.gz | ||
- | test -f $f.5.gz && mv $f.5.gz $f.6.gz | ||
- | test -f $f.4.gz && mv $f.4.gz $f.5.gz | ||
- | test -f $f.3.gz && mv $f.3.gz $f.4.gz | ||
- | test -f $f.2.gz && mv $f.2.gz $f.3.gz | ||
- | test -f $f.1.gz && mv $f.1.gz $f.2.gz | ||
- | test -f $f.0 && mv $f.0 $f.1 && gzip $f.1 | ||
- | |||
- | cp -p $f $f.0 | ||
- | |||
- | cat /dev/null >$f | ||
- | fi | ||
- | done | ||
- | |||
- | if test -f $WEBLOG.0; then | ||
- | |||
- | TMPLOG=`mktemp / | ||
- | |||
- | logresolve < $WEBLOG.0 > $TMPLOG | ||
- | |||
- | mkdir -p $STATDIR | ||
- | |||
- | webalizer -Q -p -n" | ||
- | |||
- | rm -f $TMPLOG | ||
- | fi | ||
- | |||
- | exit 0 | ||
- | </ | ||
- | |||
- | ==Clone== | ||
- | |||
- | __First stop the container to commit any changes__ | ||
- | |||
- | < | ||
- | docker stop alpine_lunux | ||
- | docker commit alpine_linux wordpress: | ||
- | </ | ||
- | |||
- | __Container can be restarted now__ | ||
- | |||
- | < | ||
- | docker start alpine_linux | ||
- | </ | ||
- | |||
- | __Save the docker container as an image__ | ||
- | |||
- | < | ||
- | docker save -o wordpress_v1.tar wordpress: | ||
- | </ | ||
- | |||
- | Container image can now be used elsewhere. | ||
===Resources=== | ===Resources=== | ||
[[https:// | [[https:// | ||
+ | |||
+ | [[https:// | ||