# Docker 學習紀錄
This is a note from [docker for beginners](https://docker-curriculum.com/#getting-started).
## Manage Docker as a non-root user
1. Create the docker group.
`$ sudo groupadd docker`
2. Add your user to the docker group.
`$ sudo usermod -aG docker $USER`
-G, --groups GROUPS new list of supplementary GROUPS
-a, --append append the user to the supplemental GROUPS mentioned by the -G option without removing the user from other groups.
3. Log out and log back in so that your group membership is re-evaluated. You can also run the following command to activate the changes to groups:
`$ newgrp docker`
## Getting Started
### Images
```
// Fetch image from the Docker registry
$ docker pull
// Build image
...
// Show all the images
$ docker images
// Remove image
$ docker rmi ${image}
```
### Container
```
// Run container
$ docker run ${image} ${command}
// Show all containers that are running/ or not
$ docker ps
$ docker ps -a
// Remove container that have a status of exited
$ docker rm $(docker ps -a -q -f status=exited)
$ docker container prune
// Start the exited container
$ docker start -ai ${my_container}
```
## Webapp with Docker
### Static sites
#### Run
```
$ docker run --rm -it prakhar1989/static-site
```
`--rm` flag automatically removes the container when it exits.
`-it` flag specifies an interactive terminal which makes it easier to kill container.
```
$ docker run -d -P --name static-site prakhar1989/static-site
```
`-d` will detach our terminal
`-P` will publish all exposed ports to random ports
`--name `corresponds to a name we want to give.
#### See the port
```
$ docker port static-site
```
You can open http://localhost:32769 in your browser.
#### Stop detached container
```
$ docker stop static-site
```
### Docker compose
build docker-compose.yaml file
```
version: "3"
services:
ollama:
image: ollama/ollama:rocm
container_name: ollama
ports:
- "11434:11434"
volumes:
- ollama:/root/.ollama
- /home/sw/GitHub/Ollama/:/work/
devices:
- /dev/kfd
- /dev/dri
restart:
always
openwebui:
image: ghcr.io/open-webui/open-webui:v0.4.6
container_name: open-webui
ports:
- "3000:8080"
volumes:
- open-webui:/app/backend/data
# extra_hosts:
# - "host.docker.interanl:host-gateway"
restart:
always
volumes:
ollama:
external: true
open-webui:
external: true
```
---
## Network and Docker Network

## Find Where is the Venv in Docker
Check the Base Image Structure: Run the base image interactively to inspect the environment setup:
```
docker run -it asrock/rocm-torch:6.2.1-2.6.0 /bin/bash
```
Check for existing virtual environments inside the container:
```
find / -name "activate" 2>/dev/null
```