From b7fc235b41c4c14a5517d9f9a9c9e7b32ac7d43d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Marchal?= Date: Fri, 17 Sep 2021 02:17:23 +0200 Subject: [PATCH] Add git, modify lxc and docker --- docker.md | 39 +++++++++++++++++++------------ git.md | 13 +++++++++++ lxc.md | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 14 deletions(-) create mode 100644 git.md create mode 100644 lxc.md diff --git a/docker.md b/docker.md index 0de2a12..1ffcc8c 100644 --- a/docker.md +++ b/docker.md @@ -1,20 +1,31 @@ -Show running containers -`docker ps` -Show all existing containers -`docker ps -a` -Access a container -`docker exec -it CONTAINER bash` +# Docker -Remove a volume not associated with any container -`docker volume prune` +## Manage containers -Start a container from a compose file -`docker-compose up -d` +* Start a container from a compose file: `docker-compose up -d` +* Access a container: `docker exec -it CONTAINER bash` -Backup a database from a container -`docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql` +* Remove a volume not associated with any container: `docker volume prune` -Restore a database to a container -`cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE` +## List containers + +* Show running containers: `docker ps` + +* Show all existing containers: `docker ps -a` + +## Database + +* Backup a database from a container + `docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql` + +* Restore a database to a container + `cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE` + +## Specifics use + +### Nextcloud + +* Manage a Nextcloud Docker instance + `docker exec -u www-data -it nextcloud-web php occ maintenance:mode --off` diff --git a/git.md b/git.md new file mode 100644 index 0000000..d1940c2 --- /dev/null +++ b/git.md @@ -0,0 +1,13 @@ +# Git + +## Submodules + +* Initialize a git submodule after a clone + `git submodule update --init --recursive` + +* Update a git submodule + `git submodule update` + +* Update the reference to the last commit in the submodule inside the parent repository + `git submodule update --remote --merge` + diff --git a/lxc.md b/lxc.md new file mode 100644 index 0000000..f760280 --- /dev/null +++ b/lxc.md @@ -0,0 +1,68 @@ +# LXC + +## Create a container + +* `$ lxc launch [distribution] [name]` + * **example:** `$ lxc launch images:debian/10 test-container` + +## List available distribution images + +* `$ lxc image list images:` + +## List existing containers + +* `$ lxc list` + +``` ++----------------+---------+----------------------+---------------------------+------------+-----------+ +| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS | ++----------------+---------+----------------------+---------------------------+------------+-----------+ +| alpine | STOPPED | | | PERSISTENT | 1 | ++----------------+---------+----------------------+---------------------------+------------+-----------+ +| debian | STOPPED | | | PERSISTENT | 0 | ++----------------+---------+----------------------+---------------------------+------------+-----------+ +| ubuntu | STOPPED | | | PERSISTENT | 3 | ++----------------+---------+----------------------+---------------------------+------------+-----------+ +| minimal | RUNNING | 10.10.10.10 (eth0) | fd80::0000 (eth0) | PERSISTENT | 0 | ++----------------+---------+----------------------+---------------------------+------------+-----------+ +| test-container | STOPPED | | | PERSISTENT | 0 | ++----------------+---------+----------------------+---------------------------+------------+-----------+ +``` + +## Change state + +* Start a container: `$ lxc start [container]` +* Stop a container: `$ lxc stop [container]` + +## Access a container + +* `$ lxc exec [repository] [command]` + * **example:** `$ lxc exec test-container bash` + +## Snapshots + +* Create a snapshot: `$ lxc snapshot [container] [snapshot_name]` + * **example:** `$ lxc snapshot test-container base_state` +* Restore a snapshot: `$ lxc restore [container] [snapshot_name]` + * **example:** `$ lxc restore test-container base_state` + +## Copy files + +* To a container: `$ lxc file push [/local/files/to/copy] [container]/[destination/path]` + * **example:** `$ lxc file push -r /home/user/files test-container/root` (add `-r` to copy a folder) +* From a container: `$ lxc file pull [container][/files/to/copy] [destination/path]` + * **example:** `$ lxc file pull test-container/root/files .` + +## Privileged containers + +This feature is only available when LXD is installed. + +* When creating a container: `$ lxc launch [distribution] [name] -c security.privileged=true` + * Please note that this parameter apparently cannot be changed later. + +When a container is privileged, we can share folders from the host to the container, in a **read-write** manner. We can still add a shared folder with unprivileged containers, but they will be **read-only** (chowned at nobody:nobody). + +Note that you will need to change the group and user of the folder to the corresponding one of lxd (use `id lxd` to know it) before adding it. + +* Adding a shared folder: `$ lxc config device add [container] [share_name] disk source=[/host/path/] path=[/container/path]` + * **example:** `$ lxc config device add test-container home_dir disk source=/home/$USER path=/home/ubuntu` \ No newline at end of file