Docker

Install:

安裝完成後需要sudo usermod -aG docker [user]後重新登錄,以非root用戶使用docker。

docker run command時,報docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?檢查docker是否已啓動,ps -aux | grep docker,若已啓動依然報此錯誤,一般是用戶導致的,可sudo執行,或添加docker用戶。


docker run hello-world

run:創建並運行一個docker container,container是極簡的linux操作系統

hello-world:加載名爲hello-world的image進這個container,image是加載進container的程序


Docker Hub:全球共享docker image庫。


構建image:

mkdir mydocker && cd mydocker

vim Dockerfile

docker build -t docker-whale .    # 讀取當前目錄下的Dockerfile,構建名爲docker-whale的image

docker run docker-whale

docker images

# REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

# docker-whale           latest              bd523f778016     About an hour ago   274.5 MB
# hello-world               latest              94df4f0ce8a4        3 weeks ago           967 B
# docker/whalesay     latest               6b362a9f73eb     12 months ago         247 MB

docker tag bd523f778016 [account]/docker/whalesay latest   # 用image-id和docker-hub-account和image名稱標記image

docker images

REPOSITORY             TAG                 IMAGE ID            CREATED             SIZE

# docker-whale           latest              bd523f778016     About an hour ago   274.5 MB
# yimzncy/docker-whale   latest        bd523f778016     About an hour ago   274.5 MB
# hello-world               latest              94df4f0ce8a4        3 weeks ago           967 B
# docker/whalesay     latest               6b362a9f73eb     12 months ago         247 MB

sudo docker login --username=[account] --email=[account]@gmail.com   # 登錄docker hub

docker push docker/whalesay   # push image

docker rmi -f bd523f778016/docker-whale   # 刪除image可用id或name

docker run [account]/docker/whalesay   # pull && load image


MORE:

https://docs.docker.com/docker-hub/


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章