[轉]My list of helpful docker commands

https://gist.github.com/garystafford/f0bd5f696399d4d7df0f docker exec -it $(docker container ls | grep 'pattern' | awk '{print $1}') bin/bash docker ps -a --no-trunc | grep 'pattern' | awk '{print $1}' | xargs -r --no-run-if-empty docker rm docker images -a | grep 'pattern' | awk '{print $3}' | xargs docker rmi ############################################################################### # Helpful Docker commands and code snippets ############################################################################### ### CONTAINERS ### docker stop $(docker ps -a -q) #stop ALL containers docker rm -f $(docker ps -a -q) # remove ALL containers docker rm -f $(sudo docker ps --before="container_id_here" -q) # can also filter # exec into container docker exec -it $(docker container ls | grep '' | awk '{print $1}') sh # exec into container on windows with Git Bash winpty docker exec -it $(docker container ls | grep '' | awk '{print $1}') sh # helps with error: 'unexpected end of JSON input' docker rm -f $(docker ps -a -q) # Remove all in one command with --force docker exec -i -t "container_name_here" /bin/bash # Go to container command line # to exit above use 'ctrl p', 'ctrl q' (don't exit or it will be in exited state) docker rm $(docker ps -q -f status=exited) # remove all exited containers ### IMAGES ### # list images and containers docker images | grep "search_term_here" # remove image(s) (must remove associated containers first) docker rmi -f image_id_here # remove image(s) docker rmi -f $(docker images -q) # remove ALL images!!! docker rmi -f $(docker images | grep "^" | awk '{print $3}') # remove all images docker rmi -f $(docker images | grep 'search_term_here' | awk '{print $1}') # i.e. 2 days ago docker rmi -f $(docker images | grep 'search_1\|search_2' | awk '{print $1}') ### DELETE BOTH IMAGES AND CONTAINERS ### docker images && docker ps -a # stop and remove containers and associated images with common grep search term docker ps -a --no-trunc | grep "search_term_here" | awk "{print $1}" | xargs -r --no-run-if-empty docker stop && \ docker ps -a --no-trunc | grep "search_term_here" | awk "{print $1}" | xargs -r --no-run-if-empty docker rm && \ docker images --no-trunc | grep "search_term_here" | awk "{print $3}" | xargs -r --no-run-if-empty docker rmi # stops only exited containers and delete only non-tagged images docker ps --filter 'status=Exited' -a | xargs docker stop docker images --filter "dangling=true" -q | xargs docker rmi ### DELETE NETWORKS AND VOLUMES ### # clean up orphaned volumes docker volume rm $(docker volume ls -qf dangling=true) # clean up orphaned networks docker network rm $(docker network ls -q) ### NEW IMAGES/CONTAINERS ### # create new docker container, ie. ubuntu docker pull ubuntu:latest # 1x pull down image docker run -i -t ubuntu /bin/bash # drops you into new container as root ### OTHER ### # install docker first using directions for installing latest version # https://docs.docker.com/installation/ubuntulinux/#ubuntu-trusty-1404-lts-64-bit # other great tips: http://www.centurylinklabs.com/15-quick-docker-tips/ # fix fig / docker config: https://gist.github.com/RuslanHamidullin/94d95328a7360d843e52

2018-12-24 · 3 min · 480 words · Me

gitlab old version backup restore upgrade

check version http://xxx.xxx.xxx.xxx/help 1. https://packages.gitlab.com/gitlab/gitlab-ce 2. example https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-9.5.4-ce.0.el7.x86_64.rpm curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash sudo yum install gitlab-ce-9.5.4-ce.0.el7.x86_64 ps: https://docs.gitlab.com/omnibus/manual_install.html 3. http://sueboy.blogspot.com/2018/12/gitlab.html sudo nano /etc/gitlab/gitlab.rb 可以在裡面找到external_url sudo gitlab-ctl reconfigure sudo gitlab-ctl status 4. open firewall firewall-cmd –zone=public –add-port=80/tcp –permanent firewall-cmd –list-all –permanent 5. backup restore https://docs.gitlab.com/ee/raketasks/backup_restore.html https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/raketasks/backup_restore.md 6. upgrade https://docs.gitlab.com/omnibus/update/ gitlab Maintenance Policy Upgrade recommendations https://docs.gitlab.com/ee/policy/maintenance.html#upgrade-recommendations 9.5 to 10 https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/update/9.5-to-10.0.md ================================ 目前已經在測試環境模擬過,安全可行方式: 建立一台新的centos 灌gitlab 9.5.4,還原 目前9.5.4,確認是否能正常執行gitlab 開始升級 9.5.4 -> 11.5.5 會失敗,必需 9.5.4 -> 9.5.10 -> 10.8.7 -> 11.3.4 -> 11.5.5,必需按照這個步驟升級4次 gitlab 11.5.5升級完後,請人員操作測試是否有問題,沒問題後,再把舊的關閉,切換ip 個人帳號操作看起來沒有問題,需要其他人測試才能更清楚是否有其他問題 ...

2018-12-22 · 1 min · 86 words · Me

[轉]【Flutter踩雷心得】楊維中 (R1-Day2) MOPCON 2018

2018-12-22 · 0 min · 0 words · Me

A script to backup GitLab repositories.

https://gist.github.com/avence12/70fc35963444d096d1bdb558b252327a https://www.lightblue.asia/gitlab-backup-script/?doing_wp_cron=1545378263.6541728973388671875000 Change: 1. http token: kzy3x2TSeukztpvzBiYA token from gitlab Personal Access Token, Don’t use Account Private Tokens. Need to product Personal Access Token GLAB_GIT_CLONE_CMD="git clone --quiet --mirror git@${GLAB_GITHOST}:" GLAB_GIT_CLONE_CMD="git clone --quiet --mirror http://oauth2:${GLAB_TOKEN}@${GLAB_GITHOST}/" PS:GLAB_TOKEN use in GLAB_PROJ_API, Personal Access Token or Account Private Tokens both is ok REPO have bug:REPO have " must remove, so add line under https://stackoverflow.com/questions/13570327/how-to-delete-a-substring-using-shell-script for REPO in $REPOLIST; do for REPO in $REPOLIST; do REPO=${REPO%\"} GLAB_GITHOST、GLAB_API have gitlab.com change => ip:port or domain ...

2018-12-21 · 3 min · 432 words · Me

新版gitlab安裝

https://xenby.com/b/131-%E6%8E%A8%E8%96%A6-gitlab%E5%AE%89%E8%A3%9D%E8%88%87%E5%9F%BA%E6%9C%AC%E8%A8%AD%E5%AE%9A%E6%95%99%E5%AD%B8 https://gitlab.com/gitlab-org/gitlab-ce/#installation sudo nano /etc/gitlab/gitlab.rb 可以在裡面找到external_url sudo gitlab-ctl reconfigure

2018-12-21 · 1 min · 9 words · Me