Add git, modify lxc and docker

This commit is contained in:
Théo Marchal 2021-09-17 02:17:23 +02:00
parent 971be62ca7
commit b7fc235b41
3 changed files with 106 additions and 14 deletions

View File

@ -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`

13
git.md Normal file
View File

@ -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`

68
lxc.md Normal file
View File

@ -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`