Files
42_INT_13_inception/README.md
2022-09-05 11:41:06 +02:00

190 lines
9.3 KiB
Markdown

# inception
---
## git next commit
+ in makefile added -d to up in detach
+ in makefile added close-nginx
+ in makefile changed clean doesnt rm-images
---
## questions
- ? what means mounted in "a file or directory on the host machine is mounted into a container" ?
- ? why the volumes cannot be modify outside docker ?
- ? `rm -rf /var/lib/apt/lists/*` ?
---
## nginx basics
- `sudo netstat -tulpn` to print network connections and see if nginx is running
- or : `ps -ax | grep nginx`
- `sudo nginx -s quit` to stop it
- `sudo docker system prune -af --volumes` -> `-a` also unused images, `-f` without prompt for confirmation
- remove stopped containers
- remove unused networks
- remove unused images
- remove build cache
- `sudo docker ps -q` all runnings containers
- `sudo docker stop $(sudo docker ps -q)` stop all runnings containers
---
## Docker basics
- the container posess its own filesystem
- we need to copy the files it uses inside this filesystem
- we can do that with COPY
**build and run a docker image**
- `sudo docker build --tag <name> .`
- `sudo docker run <name>`
- `sudo docker images` to list docker images
- `sudo docker image rm <number>`
- `sudo docker ps` to list docker processes
- `sudo docker ps rm <name>`
**execute a docker-compose file**
- `sudo docker-compose up`
- or `sudo docker-compose -f ./path up` to specify a path
---
## ressources
- [download alpine linux](https://alpinelinux.org/downloads/)
- [dockerhub alpine image](https://hub.docker.com/_/alpine)
#### docker :
- [docker starter guide](https://docs.docker.com/get-started/)
- [docker glossaire](https://docs.docker.com/glossary/)
- [Dockerfile syntaxe](https://docs.docker.com/engine/reference/builder/)
- [determine the parent image](https://forums.docker.com/t/determine-the-parent-image/48611)
- [docker image from scratch](https://codeburst.io/docker-from-scratch-2a84552470c8)
- [build context and image context](https://stackoverflow.com/questions/55108649/what-is-app-working-directory-for-a-dockerfile/55109065#55109065)
- [run without sudo on linux](https://docs.docker.com/engine/install/linux-postinstall/)
- [run docker deamon rootless](https://docs.docker.com/engine/security/rootless/)
- [dangling images '<none>'](https://projectatomic.io/blog/2015/07/what-are-docker-none-none-images/)
- [go inside docker to debug it](https://docs.docker.com/engine/reference/commandline/container_exec/)
- `docker exec -ti <container-name> bash` to run bash inside a running container
- [docker CMD vs ENTRYPOINT](https://phoenixnap.com/kb/docker-cmd-vs-entrypoint)
- [use env variable with compose](https://docs.docker.com/compose/environment-variables/)
###### docker pid 1
- nginx by default will create some child process (a master and some workers), then it quits (doc ?)
- when the first process of a docker container exit, the container exit (doc ?)
- so we must tell nginx to not go background : "-g 'daemon off'"
- [pid1 docker problem](https://blog.phusion.nl/2015/01/20/docker-and-the-pid-1-zombie-reaping-problem/)
- [official nginx docker image](https://hub.docker.com/_/nginx/)
- "If you add a custom CMD in the Dockerfile, be sure to include -g daemon off; in the CMD in order for nginx to stay in the foreground, so that Docker can track the process properly (otherwise your container will stop immediately after starting)!"
- [SO discussion on "-g 'daemon off'"](https://stackoverflow.com/questions/18861300/how-to-run-nginx-within-a-docker-container-without-halting)
- "When PID 1 exits, the container will exit" (where is says in the doc ?)
- ["By design, containers started in detached mode exit when the root process used to run the container exits"](https://docs.docker.com/engine/reference/run/#detached--d)
###### install and use docker and compose
- [how to install docker engine](https://docs.docker.com/engine/install/ubuntu/)
- [github releases](https://github.com/docker/compose/releases)
- [install last version of compose manually](https://docs.docker.com/compose/install/compose-plugin/#install-the-plugin-manually)
- [install manually SO discussion](https://stackoverflow.com/questions/57456212/error-version-in-docker-compose-yml-is-unsupported)
- [correct release version name for download with a 'v'](https://stackoverflow.com/questions/58747879/docker-compose-usr-local-bin-docker-compose-line-1-not-command-not-found)
- the version installed with apt is 1.17.1, way out of date
###### remove old versions
- `sudo apt remove docker docker-engine docker.io containerd runc`
###### preparing directory
- `sudo apt update`
- `sudo apt install ca-certificates curl gnupg lsb-release`
- `sudo mkdir -p /etc/apt/keyrings`
- `curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg`
- `echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null`
###### installing docker engine
- `sudo apt update`
- `sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin`
###### check if installation worked
- `sudo docker run hello-world`
###### installing docker compose (checked version on github release, see above)
- notice the 'v' below, before the version name (docker doc has it wong)
- `sudo curl -L "https://github.com/docker/compose/releases/download/v2.10.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose`
- `sudo chmod +x /usr/local/bin/docker-compose`
###### volumes vs bind mounts :
- [docker doc: use volumes](https://docs.docker.com/storage/volumes/)
- [docker doc: use bind mounts](https://docs.docker.com/storage/bind-mounts/)
- [comparison volume vs bind mounts](https://devopscook.com/docker-volumes-vs-bind-mounts/)
- [fundamentals use of volumes and bind mounts](https://medium.com/dlt-labs-publication/bind-mounts-volumes-in-docker-81523303cbb4)
- [how volumes and bind mounts are really differents](https://serverfault.com/questions/996785/docker-volumes-vs-mount-binds-what-are-the-use-cases)
- bind mounts are normal files anywhere on the computer, that docker container can access with absolut path and modify. They can also be modified without docker, since they are juste files
- volumes are only modifiable by docker, they don't need an absolut path, and they are not dependent of host architecture
###### psswd in dockerfile :
- [SO securing passwords in dockerfiles](https://stackoverflow.com/questions/22651647/docker-and-securing-passwords)
#### nginx
- [nginx begginer guide](https://hub.docker.com/_/nginx/)
- [nginx all directives for conf file](https://nginx.org/en/docs/dirindex.html)
- [conf file in conf.d or sites-available ?](https://serverfault.com/questions/527630/difference-in-sites-available-vs-sites-enabled-vs-conf-d-directories-nginx#answer-870709)
- [command line parameters](https://nginx.org/en/docs/switches.html)
- `sudo nginx -t` will launch a test to evaluate config file
#### openssl
- [openssl faq](https://www.openssl.org/docs/faq.html)
- [openssl req man](https://www.openssl.org/docs/man1.0.2/man1/openssl-req.html)
- [SO discussion about ssl self signed certificate and becoming a CA](https://stackoverflow.com/questions/10175812/how-to-generate-a-self-signed-ssl-certificate-using-openssl)
#### wordpress
- [install wp](https://wordpress.org/support/article/how-to-install-wordpress/#detailed-instructions)
- [install wp with wp-cli](https://make.wordpress.org/cli/handbook/how-to-install/)
###### install wp
- wget https://wordpress.org/latest.tar.gz
- tar -xzvf latest.tar.gz
#### mariadb
- [mariadb tutorial](https://www.mariadbtutorial.com/)
- server vs client :
- "server" runs in the background and listen for inputs
- "client" interpret the commands to communicate with "server"
- sudo apt install mariadb-client mariadb-server
- [wiki ubuntu mariadb](https://doc.ubuntu-fr.org/mariadb)
- [list of directives](https://mariadb.com/kb/en/sql-statements/)
- [ERROR 1698 (28000): Access denied for user 'root'@'localhost'](https://stackoverflow.com/questions/39281594/error-1698-28000-access-denied-for-user-rootlocalhost)
- [ERROR 1698 (28000): Access denied for user 'root'@'localhost' 2](https://askubuntu.com/questions/763336/cannot-enter-phpmyadmin-as-root-mysql-5-7#answer-1003892)
- [meaning of % SO](https://stackoverflow.com/questions/12931991/mysql-what-does-stand-for-in-host-column-and-how-to-change-users-password)
- [meaning of % doc](https://doc.ubuntu-fr.org/mysql#connexions_entrantes)
- `%` means all entrant connections, while `localhost` means only localhost connections
- [mysql commande line](https://mariadb.com/kb/en/mysql-command-line-client/)
- [use mysql in script](https://stackoverflow.com/questions/59608632/mariadb-create-database-and-execute-sql-script-without-character-from-the)
###### mariadb basic commands :
- create user :
```
# mysql -u root
use mysql;
CREATE USER 'some_user'@'%' IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON *.* TO 'some_user'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
```
- show users :
```
SELECT User, Host, plugin FROM mysql.user;
```
- delete user :
```
DROP USER <name>;
```
- show databases :
```
SHOW DATABASES;
```
- delete database :
```
DROP DATABASE <name>;
```
#### php-fpm
- [](https://en.wikipedia.org/wiki/FastCGI)