Services/Docker: Difference between revisions
Jump to navigation
Jump to search
| (46 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
= Clean Docker = | = Clean Docker = | ||
{| class="wikitable" | {| class="wikitable" | ||
! TODO || Command | ! TODO || Command | ||
|- | |||
| Run debian image on Windows || | |||
<syntaxhighlight lang="bash"> | |||
# Git Bash | |||
winpty docker run --name=debian0 -it debian:12 | |||
# Power Shell | |||
docker run --name=debian0 -it debian:12 | |||
</syntaxhighlight> | |||
|- | |||
| Open shell of running container || | |||
<syntaxhighlight lang="bash"> | |||
docker exec -it mwdev-mediawiki-1 /bin/bash | |||
</syntaxhighlight> | |||
|- | |||
| Copy file from running container || | |||
<syntaxhighlight lang="bash"> | |||
docker cp mwdev-mediawiki-1:/var/www/data/my_wiki.sqlite . | |||
</syntaxhighlight> | |||
|- | |||
| Build image || | |||
<syntaxhighlight lang="bash"> | |||
docker build . | |||
docker build -t gdtile:2.1 . | |||
docker tag c8abdb693116 gdtile:2.1 | |||
</syntaxhighlight> | |||
|- | |- | ||
| Remove exited containers || | | Remove exited containers || | ||
< | <syntaxhighlight lang="bash"> | ||
docker rm $(docker ps -f 'status=exited' -q) | docker rm $(docker ps -f 'status=exited' -q) | ||
sudo docker rm $(sudo docker ps -f 'status=exited' -q) | sudo docker rm $(sudo docker ps -f 'status=exited' -q) | ||
</ | </syntaxhighlight> | ||
|- | |- | ||
| Remove unused images || | | Remove unused images || | ||
< | <syntaxhighlight lang="bash"> | ||
docker rmi $(docker images -f "dangling=true" -q) | docker rmi $(docker images -f "dangling=true" -q) | ||
sudo docker rmi $(sudo docker images -f "dangling=true" -q) | sudo docker rmi $(sudo docker images -f "dangling=true" -q) | ||
</ | </syntaxhighlight> | ||
|- | |- | ||
| run and start it again || | | run and start it again || | ||
< | <syntaxhighlight lang="docker"> | ||
docker run --name sandbox0 \ | docker run --name sandbox0 \ | ||
--volume a:b \ | --volume a:b \ | ||
-it alpine:3.11 | -it alpine:3.11 | ||
docker start -i sandbox0 | docker start -i sandbox0 | ||
</ | </syntaxhighlight> | ||
|- | |- | ||
| Make apt faster || | | Make apt faster || | ||
< | <syntaxhighlight lang="docker"> | ||
FROM ubuntu:20.04 | FROM ubuntu:20.04 | ||
RUN sed -i 's/\(archive\|security\).ubuntu.com/free.nchc.org.tw/' /etc/apt/sources.list | RUN sed -i 's/\(archive\|security\).ubuntu.com/free.nchc.org.tw/' /etc/apt/sources.list | ||
RUN apt update | RUN apt update | ||
</ | </syntaxhighlight> | ||
< | <syntaxhighlight lang="bash"> | ||
# In host | # In host | ||
docker run -it ubuntu:20.04 | docker run -it ubuntu:20.04 | ||
| Line 39: | Line 66: | ||
sed -i 's/\(archive\|security\).ubuntu.com/free.nchc.org.tw/' /etc/apt/sources.list | sed -i 's/\(archive\|security\).ubuntu.com/free.nchc.org.tw/' /etc/apt/sources.list | ||
apt update | apt update | ||
</ | </syntaxhighlight> | ||
|- | |- | ||
| Run || | | Run || | ||
< | <syntaxhighlight lang="docker"> | ||
# Mapping directory on Windows, do not use ~ | # Mapping directory on Windows, do not use ~ | ||
docker run -v C:\Users\User\repos\something:/docroot -it someimage bash | docker run -v C:\Users\User\repos\something:/docroot -it someimage bash | ||
docker run -v %USERPROFILE%\repos\webserv:/docroot -it webserv-compose_web bash | docker run -v %USERPROFILE%\repos\webserv:/docroot -it webserv-compose_web bash | ||
</ | </syntaxhighlight> | ||
|- | |||
| test || | |||
<syntaxhighlight lang="docker"> | |||
docker ps --size --all | |||
</syntaxhighlight> | |||
|- | |||
| logs || | |||
<syntaxhighlight lang="docker"> | |||
docker ps logs -ft container | |||
</syntaxhighlight> | |||
|} | |||
= Dockerfile Debugging = | |||
{| class="wikitable" | |||
! TODO || Command | |||
|- | |||
| Verify environment variable<br>(stdout won't be printed) || | |||
<syntaxhighlight lang="docker"> | |||
RUN export NVM_DIR="$HOME/.nvm" | |||
RUN echo "NVM_DIR=$NVM_DIR" >&2 | |||
</syntaxhighlight> | |||
|- | |||
| || | |||
<syntaxhighlight lang="docker"> | |||
docker compose build --progress=plain | |||
</syntaxhighlight> | |||
|- | |||
| || | |||
<syntaxhighlight lang="docker"> | |||
docker compose build --no-cache --progress=plain | |||
</syntaxhighlight> | |||
|} | |} | ||
Latest revision as of 09:39, 26 September 2025
Clean Docker
| TODO | Command |
|---|---|
| Run debian image on Windows |
# Git Bash
winpty docker run --name=debian0 -it debian:12
# Power Shell
docker run --name=debian0 -it debian:12
|
| Open shell of running container |
docker exec -it mwdev-mediawiki-1 /bin/bash
|
| Copy file from running container |
docker cp mwdev-mediawiki-1:/var/www/data/my_wiki.sqlite .
|
| Build image |
docker build .
docker build -t gdtile:2.1 .
docker tag c8abdb693116 gdtile:2.1
|
| Remove exited containers |
docker rm $(docker ps -f 'status=exited' -q)
sudo docker rm $(sudo docker ps -f 'status=exited' -q)
|
| Remove unused images |
docker rmi $(docker images -f "dangling=true" -q)
sudo docker rmi $(sudo docker images -f "dangling=true" -q)
|
| run and start it again |
docker run --name sandbox0 \
--volume a:b \
-it alpine:3.11
docker start -i sandbox0
|
| Make apt faster |
FROM ubuntu:20.04
RUN sed -i 's/\(archive\|security\).ubuntu.com/free.nchc.org.tw/' /etc/apt/sources.list
RUN apt update
# In host
docker run -it ubuntu:20.04
# In container
sed -i 's/\(archive\|security\).ubuntu.com/free.nchc.org.tw/' /etc/apt/sources.list
apt update
|
| Run |
# Mapping directory on Windows, do not use ~
docker run -v C:\Users\User\repos\something:/docroot -it someimage bash
docker run -v %USERPROFILE%\repos\webserv:/docroot -it webserv-compose_web bash
|
| test |
docker ps --size --all
|
| logs |
docker ps logs -ft container
|
Dockerfile Debugging
| TODO | Command |
|---|---|
| Verify environment variable (stdout won't be printed) |
RUN export NVM_DIR="$HOME/.nvm"
RUN echo "NVM_DIR=$NVM_DIR" >&2
|
docker compose build --progress=plain
| |
docker compose build --no-cache --progress=plain
|