Docker 常用指令

Env:

  • 安裝與啟動

    在安裝 Docker 前先更新一下 YUM Repository:

    # yum -y update

    更新 YUM Repository 後可以安裝 Docker 及其相關套件:

    # yum -y install docker docker-registry

    安裝好 Docker 後, 啟動 Docker 及設定 Docker 開機自動啟動:

    # systemctl enable docker

    # systemctl start docker

    要檢查 Docker 是否正確啟動, 可用 status 選項:

    # systemctl status docker.service

  • 登入 Docker hub to push or commit images

    # docker login

  • Show host IP

ip addr show docker0 | grep -Po 'inet \K[\d.]+'

Build image:

  • Create a file with multiple lines content in Dockerfile

RUN echo $'[repo] \n\
name            = YUM Repository \n\
baseurl         = https://example.com/packages/ \n\
enabled         = 1 \n\
gpgcheck        = 0' > /etc/yum.repos.d/Repo.repoxyz

Build container:

  • Start and attach to container

docker start -ai {{container_id}}
#or start and docker exec 
  • Build and expose port to container

  • docker run -d -p 8080:80 {image}

  • Build and go into container bash

    docker run -t -i ubuntu:12.04 bash

  • Build, expose port and go into container bash

    docker run -itd -p 8080:80 {image} bash 

    # -p host_port:container_port

About Image:

  • 清除 <none> images

docker rmi $(docker images -f "dangling=true" -q)
  • 更新 image

  • docker commit -m "Setup to Jupyter truly" -a "John" {containerId} {image}

  • Push to Repository

    docker push {image}

  • Check the files permission in docker image

    docker run –rm -ti –entrypoint sh {image} -c "ls -alF /usr/local/bin/"

About Container:

  • Remove dead container

    • Linux

sudo rm -rf /var/lib/docker/<storage_driver>/{CONTAINER ID}/
    • Windows

del D:\ProgramData\docker\containers\{CONTAINER ID}
del D:\ProgramData\docker\windowsfilter\{CONTAINER ID}
  • Check screen log output

docker logs -f <CONTAINER> --tail {lineNumber}
  • List all the containers

    docker ps -aq

  • Stop all running containers

    docker stop $(docker ps -aq)

  • Remove all containers

    docker rm $(docker ps -aq)

  • Remove all images

    docker rmi $(docker images -q)

  • Copy file from host to container

    docker cp foo.txt mycontainer:/foo.txt

    from container to host

    docker cp mycontainer:/foo.txt foo.txt

  • 進入 Running Container bash

    docker exec -i -t <CONTAINER_ID> bash

    docker exec -i -t <CONTAINER_ID> sh

  • 進入 Stopped(Exited) container bash

docker images   # Find the {imageId} of exited container
docker run -it --entrypoint=sh {imageId}

# not verify? 
docker start -ai {CONTAINER_ID} bash
  • 修改初始 command 並 start new container

    docker run -ti –entrypoint=sh <IMAGE_NAME>

148 Comments

53 Trackbacks / Pingbacks

  1. stromectol tablets 3 mg
  2. ivermectin
  3. cialis tadalafil
  4. furosemide 25 mg
  5. ivermectin japan
  6. cialis price costco
  7. generic cialis singapore
  8. viagra cialis
  9. ivermectin 4 mg
  10. antiviral medicament
  11. buy cialis online
  12. discount tadalafil
  13. stromectol 3 mg tablets price
  14. viagra dosage
  15. generic cialis
  16. zone free online casino games
  17. natural viagra alternatives
  18. viagra canada purchase
  19. cialis pills for men
  20. borgata casino pa
  21. buy ivermectin on line
  22. cialis super active
  23. ivermectin brand
  24. usa no deposit casino bonus codes
  25. generic for viagra
  26. tadalafil cialis
  27. cialis online pharmacy
  28. ivermectin for horses
  29. eurocasino
  30. eurocasino
  31. stromectol 3mg tablets
  32. ivermectin for covid
  33. what is ivermectin made from
  34. madridbet
  35. lucky land slots play now
  36. ivermectin use in humans
  37. stromectol price
  38. online ivermectin
  39. merck and ivermectin
  40. stromectol covid
  41. ivermectin 3mg dose
  42. child porn
  43. ivermectin 4000
  44. mylan tadalafil
  45. ivermectin tablet price
  46. ivermectin cost australia
  47. ivermectin tabletten für menschen kaufen
  48. bahis siteleri
  49. side effects for ivermectin
  50. 2consolidation
  51. ivermectin pills for humans
  52. buy propecia cheap uk
  53. propecia tablets buy online

Leave a Reply

Your email address will not be published.