What's the Point of Docker?
What's the Point of Docker?
Prune images
perge images
docker image prune -a
Docker Hub
Docker Hub allows you to share and save your custom images and load a library of existing images. Link
Installing Docker on Ubuntu 16, 18, 20
ubuntu 18 command line install
guide to installing docker on ubuntu 20
Pi 400 Docker
I tried getting docker up and running also on the pi400 but as its arm based i came across some issues running normal docker containers, assuming this is due to the images being intel or amd based.
Local domain
To create a .local domain, install Avahi Daemon on your Pi;
sudo apt-get install avahi-daemon
By default, the hostname is raspberrypi.
Install Docker on Rasberry Pi
install docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker ${USER}
check if its in the group
groups ${USER}
su the user or logout and back in
test if docker is working
docker version
docker info
docker run hello-world
docker image rm hello-world
Docker Compose on pi400
sudo apt-get install libffi-dev libssl-dev
sudo apt install python3-dev
sudo apt-get install -y python3 python3-pip
sudo pip3 install docker-compose
sudo systemctl to enable Docker??
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
apt-cache policy docker-ce
sudo apt install docker-ce
sudo systemctl status docker
Docker Installing
Docker Running
sudo usermod -aG docker kruxor
sudo usermod -aG docker ${USER}
su - ${USER}
groups
docker info
docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:10d7d58d5ebd2a652f4d93fdd86da8f265f5318c6a73cc5b6a9798ff6d2b2e67
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
docker search ubuntu
docker pull ubuntu
show images
docker images
docker run ubuntu
run ubuntu image with an interactive shell
docker run -it ubuntu
install node on this new instance of ubuntu
copy the instance id as well
docker run -it ubuntu
#007f6db6d204
apt update
apt install nodejs
node -v
#Any changes you make inside the container only apply to that container.
show all containers
docker ps -a
docker ps -l
#start a container by id
docker start 007f6db6d204
docker run -it sleepy_wiles
docker run -it 007f6db6d204
commit changes to image
requires a docker hub user id
docker commit -m "What you did to the image" -a "Author Name" container_id repository/new_image_name
docker commit -m "added Node.js" -a "sammy" d9b100f2f636 sammy/ubuntu-nodejs
enable docker auto start on restart of the vm
$ sudo systemctl enable docker
install docker compose
apt install docker-compose
get a basic lamp stack running on docker with local php files
mkdir $HOME/apache && cd $HOME/apache
printf '<?php phpinfo(); ?>' > info.php
docker run -d --name=apache -p 8085:80 -v $HOME/apache:/var/www/html php:apache
test it.
nerd2.kruxor.com:8085
running but getting error
http://nerd2.kruxor.com:8085/
http://nerd2.kruxor.com:8085/info.php
working on info.php
stop and delete the image
$ docker stop apache
$ docker rm apache
$ docker rmi php:apache
install and run wordpress...
this will create a wordpress and mysql containers and wordpress.
do a test install of wordpress and sqlserver... from here:
https://blog.ssdnodes.com/blog/getting-started-docker-vps/
mkdir wp_test && cd wp_test
nano docker-compose.yml
version: '2'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: __password__
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: __password_
container_name: wp_test_db
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8085:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: __password_g
container_name: wp_test
volumes:
db_data:
docker-compose up -d
docker ps
test:
http://nerd2.kruxor.com:8085
to save the data and shut down
docker-compose down
then need to figure out how to route nginx to the different docker containers, i guess just run them on diff ports like this:
docker run -d --name=apache -p 8085:80 -v $HOME/apache:/var/www/html php:apache
nginx proxy
mkdir nginx-proxy && cd nginx-proxy
docker network create nginx-proxy
36649645c730d7c433c85af48d3ad52fd16f4e16470c96ea7e6f0e5f1b7fb125
Setup ngix reverse proxy
Hosting multiple SSL-enabled sites with Docker and Nginx
mkdir nginx-proxy && cd nginx-proxy
docker network create nginx-proxy
db02b5af510e6e53b8d170705136fa2b8db1dac5a6f4ab3e82e400404a5d95d6
nano docker-compose.yml
version: '3'
services:
nginx:
image: nginx:1.13.1
container_name: nginx-proxy
ports:
- "80:80"
- "443:443"
volumes:
- conf:/etc/nginx/conf.d
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- certs:/etc/nginx/certs
labels:
- "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true"
dockergen:
image: jwilder/docker-gen:0.7.3
container_name: nginx-proxy-gen
depends_on:
- nginx
command: -notify-sighup nginx-proxy -watch -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
volumes:
- conf:/etc/nginx/conf.d
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- certs:/etc/nginx/certs
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro
letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: nginx-proxy-le
depends_on:
- nginx
- dockergen
environment:
NGINX_PROXY_CONTAINER: nginx-proxy
NGINX_DOCKER_GEN_CONTAINER: nginx-proxy-gen
volumes:
- conf:/etc/nginx/conf.d
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- certs:/etc/nginx/certs
- /var/run/docker.sock:/var/run/docker.sock:ro
volumes:
conf:
vhost:
html:
certs:
# Do not forget to 'docker network create nginx-proxy' before launch, and to add '--network nginx-proxy' to proxied containers.
networks:
default:
external:
name: nginx-proxy
curl https://raw.githubusercontent.com/jwilder/nginx-proxy/master/nginx.tmpl > nginx.tmpl
docker-compose up -d
docker ps
check logs with (optional)
docker logs
Get containers working with the nginx proxy
add the following to the container settings in docker compose
test this with a wordpress installation
environment:
VIRTUAL_HOST: feeds.example.com
LETSENCRYPT_HOST: feeds.example.com
LETSENCRYPT_EMAIL: foo@example.com
environment:
VIRTUAL_HOST: wp3.kruxor.com
LETSENCRYPT_HOST: wp3.kruxor.com
LETSENCRYPT_EMAIL: email_@gmail.com
networks:
default:
external:
name: nginx-proxy
expose:
- 80
Install wordpress using virtual hosts and ssl
mkdir $HOME/wp3 && cd $HOME/wp3
nano docker-compose.yml
version: "3"
services:
db_node_domain:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: __password__
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: __password__
container_name: wp_test_db
wordpress:
depends_on:
- db_node_domain
image: wordpress:latest
expose:
- 80
restart: always
environment:
VIRTUAL_HOST: wp3.kruxor.com
LETSENCRYPT_HOST: wp3.kruxor.com
LETSENCRYPT_EMAIL: __email__@gmail.com
WORDPRESS_DB_HOST: db_node_domain:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: __password__
container_name: wp_test
volumes:
db_data:
networks:
default:
external:
name: nginx-proxy
docker-compose up -d
Custom Container for Core, PHP and SQLite, Nginx
https://docs.docker.com/compose/gettingstarted/
copy core files to git private and
or just zip them up and then download with curl or wget
leave the git part for another time
copy kruxor.com
tar gz something
tar -czvf ~/backup/$1.tar.gz /var/www/html/$1/
tar -czvf ~/kruxor.tar.gz /var/www/html/kruxor.com/
wget https://kruxor.com/kruxor_backup_may_2022.tar.gz
un tar gz something
tar -xf kruxor_backup_may_2022.tar.gz
docker compose for php fpm and nginx running core on proxy
version: "3"
services:
nginx:
build:
context: .
dockerfile: nginx/Dockerfile
ports:
- "8080:80"
networks:
- internal
volumes:
- ./core/:/var/www/html/
- /logs/nginx:/var/log/nginx/
php:
image: php:fpm-alpine
networks:
- internal
volumes:
- ./data/:/var/www/html
networks:
internal:
driver: bridge
i dont think you need nginx as well as its already running as a proxy image
this one should work once the virtual and lets encrypt hosts are set.
format yaml here
nano docker-compose.yml
version: "3"
services:
nginx:
build:
context: .
dockerfile: nginx/Dockerfile
ports:
- "8080:80"
volumes:
- ./core/:/var/www/html/
- /logs/nginx:/var/log/nginx/
php:
image: php:fpm-alpine
volumes:
- ./core/:/var/www/html
expose:
- 80
restart: always
environment:
VIRTUAL_HOST: nerd3.kruxor.com
LETSENCRYPT_HOST: nerd3.kruxor.com
LETSENCRYPT_EMAIL: email_@gmail.com
container_name: core_kruxor
networks:
default:
external:
name: nginx-proxy
docker-compose up -d
test on nerd3.kruxor.com
docker-compose down
try php only with route via nginx proxy - this works with ssl, but gives error
version: "3"
services:
php:
image: php:fpm-alpine
volumes:
- ./core/:/var/www/html
expose:
- 80
restart: always
environment:
VIRTUAL_HOST: nerd3.kruxor.com
LETSENCRYPT_HOST: nerd3.kruxor.com
LETSENCRYPT_EMAIL: __email__@gmail.com
container_name: core_kruxor
networks:
default:
external:
name: nginx-proxy
example config for nginx and php only
version: "3"
services:
nginx:
build:
context: .
dockerfile: nginx/Dockerfile
ports:
- "8080:80"
networks:
- internal
volumes:
- ./data/:/var/www/html/
- /logs/nginx:/var/log/nginx/
php:
image: php:fpm-alpine
networks:
- internal
volumes:
- ./data/:/var/www/html
networks:
internal:
driver: bridge
external:
name: nginx-proxy
wordpress config as example
version: "3"
services:
wordpress:
depends_on:
- db_node_domain
image: wordpress:latest
expose:
- 80
restart: always
environment:
VIRTUAL_HOST: wp3.kruxor.com
LETSENCRYPT_HOST: wp3.kruxor.com
LETSENCRYPT_EMAIL: __email__@gmail.com
WORDPRESS_DB_HOST: db_node_domain:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: _password__
container_name: wp_test
volumes:
db_data:
networks:
default:
external:
name: nginx-proxy
copy wp profile for kruxor.com
version: "3"
services:
db_node_domain:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: __password__
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: __password__
container_name: wp_test_db
wordpress:
depends_on:
- db_node_domain
image: wordpress:latest
expose:
- 80
restart: always
environment:
VIRTUAL_HOST: wp3.kruxor.com
LETSENCRYPT_HOST: wp3.kruxor.com
LETSENCRYPT_EMAIL: __email__@gmail.com
WORDPRESS_DB_HOST: db_node_domain:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: __password__
container_name: wp_test
volumes:
db_data:
networks:
default:
external:
name: nginx-proxy
Next try
version: "3"
services:
php:
image: php:fpm-alpine
volumes:
- ./core/:/var/www/html
expose:
- 80
restart: always
environment:
VIRTUAL_HOST: nerd3.kruxor.com
LETSENCRYPT_HOST: nerd3.kruxor.com
LETSENCRYPT_EMAIL: __email__@gmail.com
container_name: core_kruxor
networks:
default:
external:
name: nginx-proxy
just nginx
web:
image: nginx:latest
ports:
- "8080:80"
volumes:
- ./core:/core
- ./site.conf:/etc/nginx/conf.d/site.conf
site.conf
server {
root /core;
server_name php-docker.local;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
location / {
index index.php;
try_files $uri $uri/ @core;
expires max;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location @core {
rewrite ^/(.*)$ /index.php?p=$1;
}
}
working???...
502 error bad gateway
version: "3"
services:
web:
image: nginx:latest
ports:
- "8080:80"
expose:
- 80
volumes:
- ./core:/core
- ./site.conf:/etc/nginx/conf.d/site.conf
links:
- php
container_name: nginx_kruxor
php:
image: php:7-fpm
expose:
- 80
restart: always
volumes:
- ./core:/core
environment:
VIRTUAL_HOST: nerd3.kruxor.com
LETSENCRYPT_HOST: nerd3.kruxor.com
LETSENCRYPT_EMAIL: __email__@gmail.com
container_name: phpfpm_kruxor
networks:
default:
external:
name: nginx-proxy
try server conf with no rewrite
server {
index index.php index.html;
server_name php-docker.local;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /core;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
copy the wordpress one and remove mysql and replace wordpress with php
version: "3"
services:
php:
depends_on:
- db_node_domain
image: php:latest
expose:
- 80
restart: always
environment:
VIRTUAL_HOST: nerd3.kruxor.com
LETSENCRYPT_HOST: nerd3.kruxor.com
LETSENCRYPT_EMAIL: __email__@gmail.com
container_name: php_core
volumes:
db_data:
networks:
default:
external:
name: nginx-proxy
nginx solo
working nginx only, this works with cert
version: "3"
services:
web:
image: nginx:latest
ports:
- "8080:80"
environment:
VIRTUAL_HOST: nerd3.kruxor.com
LETSENCRYPT_HOST: nerd3.kruxor.com
LETSENCRYPT_EMAIL: __email__@gmail.com
networks:
default:
external:
name: nginx-proxy
try the php fpm on as well
moved the envionment to web rather than php
version: "3"
services:
web:
image: nginx:latest
ports:
- "8080:80"
volumes:
- ./core:/core
- ./site.conf:/etc/nginx/conf.d/site.conf
environment:
VIRTUAL_HOST: nerd3.kruxor.com
LETSENCRYPT_HOST: nerd3.kruxor.com
LETSENCRYPT_EMAIL: __email__@gmail.com
links:
- php
container_name: nginx_kruxor
php:
image: php:8-fpm
expose:
- 80
restart: always
volumes:
- ./core:/core
container_name: phpfpm_kruxor
networks:
default:
external:
name: nginx-proxy
default.conf — site.conf
server {
index index.php index.html;
server_name phpfpm.local;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /core;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Dockerise web server
version: "3"
services:
web:
image: nginx:latest
ports:
- "8080:80"
environment:
VIRTUAL_HOST: nerd3.kruxor.com
LETSENCRYPT_HOST: nerd3.kruxor.com
LETSENCRYPT_EMAIL: __email__@gmail.com
volumes:
- ./src:/var/www/html
- ./default.conf:/etc/nginx/conf.d/default.conf
links:
- php-fpm
php-fpm:
image: php:8-fpm
environment:
VIRTUAL_HOST: nerd3.kruxor.com
LETSENCRYPT_HOST: nerd3.kruxor.com
LETSENCRYPT_EMAIL: __email__@gmail.com
volumes:
- ./src:/var/www/html
links:
- web
try php fpm solo?
working!!!!WER@#$%#$%@$T
working version in ~/phpfpm via proxy with ssl
version: "3"
services:
web:
image: nginx:latest
ports:
- "8080:80"
environment:
VIRTUAL_HOST: nerd3.kruxor.com
LETSENCRYPT_HOST: nerd3.kruxor.com
LETSENCRYPT_EMAIL: __email__@gmail.com
volumes:
- ./src:/var/www/html
- ./default.conf:/etc/nginx/conf.d/default.conf
links:
- php-fpm
php-fpm:
image: php:8-fpm
environment:
VIRTUAL_HOST: nerd3.kruxor.com
LETSENCRYPT_HOST: nerd3.kruxor.com
LETSENCRYPT_EMAIL: __email__@gmail.com
volumes:
- ./src:/var/www/html
networks:
default:
external:
name: nginx-proxy
default.conf
server {
index index.php index.html;
server_name phpfpm.local;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
copy this to core and test on kruxor com
new default.conf with rewrite
/code
server {
index index.php index.html;
server_name phpfpm.local;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html;
location ~ \.php$ {
#try_files $uri =404;
try_files $uri $uri/ @core;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location @core {
rewrite ^/(.*)$ /index.php?p=$1;
}
}
new kruxor.com version for core
version: "3"
services:
web:
image: nginx:latest
ports:
- "8080:80"
environment:
VIRTUAL_HOST: nerd3.kruxor.com
LETSENCRYPT_HOST: nerd3.kruxor.com
LETSENCRYPT_EMAIL: __email__@gmail.com
volumes:
- ./core:/var/www/html
- ./default.conf:/etc/nginx/conf.d/default.conf
links:
- php-fpm
php-fpm:
image: php:8-fpm
environment:
VIRTUAL_HOST: nerd3.kruxor.com
LETSENCRYPT_HOST: nerd3.kruxor.com
LETSENCRYPT_EMAIL: __email__@gmail.com
volumes:
- ./core:/var/www/html
networks:
default:
external:
name: nginx-proxy
working, but the rewrite is not working in the default.conf, but otherwise its working ok.
core conf
/******************************/
server {
root /var/www/html/nerd3.kruxor.com;
server_name nerd3.kruxor.com;
location / {
index index.php;
try_files $uri $uri/ @core;
expires max;
}
location @core {
rewrite ^/(.*)$ /index.php?p=$1;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
/******************************/
new default.conf
server {
server_name phpfpm.local;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html;
location / {
index index.php;
try_files $uri $uri/ @core;
expires max;
}
location @core {
rewrite ^/(.*)$ /index.php?p=$1;
}
location ~ \.php$ {
#try_files $uri =404;
#try_files $uri $uri/ @core;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}