Posts

程式語言初學者 Docker 入門第七章 —— 連接埠對應與容器相連

 需要多個服務元件之容器協作運作的情況。需要多個容器之間能夠彼此存取到對方的服務。 除了網路存取,服務連線基本需求還有: 允許度應容器內應用程式的監聽埠到本地端 Host 主機 戶連機制(link)實現多個容器間內過容器名稱來快速連接。 對應連接埠來存取容器 1. 從外部存取容器應用程式 啟動容器時如果不指定連接埠對應參數,在容器外部是無法透過網路來存取容器內的各項網路應用和服務 當容器內執行一些網路應用程式,要讓外部存取這些服務時,可以用 -P 或 -p 參數來指定連接埠對應 不加 -p 參數 $ docker run -d training/webapp python app.py c1a2e0f91b6f593e13e05659dd927b391bac65711fcfd0bbac9443002763c648 $ docker run -d training/webapp python app.py de1cb4fbc539b07741821ffe3d72d7cd436fd8ed052f4d4b987e1750d46252b1 $ docker run -d training/webapp python app.py e252e4aab6b252398d7ccce756c7a020dccdf4bc1faf832e35b9c1bdf1145481 $ docker run -d training/webapp python app.py 1058336f9128a18c0663ba270550cd8102e23a4be208143de4bbb56cecf81364$ docker run -d training/webapp python app.py 可以連開好幾個都正常 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1058336f9128 training/webapp "python app.py" About a minute ago Up About a minute 5000/tc...

程式語言初學者 Docker 入門第六章 —— 資料管理 Data Volumes

 查看容器內應用程式產生的資料,對資料進行持久化儲存,甚至多個容器之間進行資料共用 容器中管理資料主要有兩種方式: 資料卷 (Data Volumes) 容器內資料直接對應到本地主機環境 資料卷容器 (Data Volume Containers) 使用特定容器來維護資料卷 資料卷 特性: 容器之間共用和重用,容器間傳遞資料將變得有效率且方便 資料修改會立即生效,無論是容器內操作還是本機上操作 資料卷的更新不會影響到 image ,把應用程式資料分離去耦合 一直存在,直到沒有容器使用,便可安全移除 1. 建立資料卷 docker create docker run 用 -v 參數 會在主機端建立一個目錄並掛載到容器內,一次使用多個 -v 可以掛載多個資料卷目錄 $ docker run -d -P --name web -v /webapp training/webapp python app.py Unable to find image 'training/webapp:latest' locally latest: Pulling from training/webapp Image docker.io/training/webapp:latest uses outdated schema1 manifest format. Please upgrade to a schema2 image for better future compatibility. More information at <https://docs.docker.com/registry/spec/deprecated-schema-v1/> e190868d63f8: Pull complete 909cd34c6fd7: Pull complete 0b9bfabab7c1: Pull complete a3ed95caeb02: Pull complete 10bbbc0fc0ff: Pull complete fca59b508e9f: Pull complete e7ae2541b15b: Pull complete 9dd97ef58ce9: Pull complete a4c...

程式語言初學者 Docker 入門第五章 —— Registry 倉庫

 集中存放 image 的地方,分成 公開 私有 💡 Registry 註冊伺服器:存放倉庫 Registry Repository image image image image Repository image image Repository image image image Repository image image image Docker Hub 公開映像檔市集 登錄 docker login ❯ docker login Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one. Username: chi811008 Password: Login Succeeded Logging in with your password grants your terminal complete access to your account. For better security, log in with a limited-privilege personal access token. Learn more at https://docs.docker.com/go/access-tokens/ 搜尋 docker search ❯ docker search python3.12 NAME DESCRIPTION STARS OFFICIAL AUTOMATED nanozoo/python3.12 0 kikikanri/python3.12 ...

程式語言初學者 Docker 入門第四章 —— 容器 Container

Container 是 image 的一個執行例 (instance) image 是靜態的唯獨檔案, container 帶有運行時需要的可寫入層。 這邊來稍微複習一下 虛擬機:模擬運行的一整套作業系統(核心 + 執行應用系統必要環境 + 系統環境)+ run app Docker 容器:獨立執行的一個或一組應用系統 + 必要執行環境 1. 建立容器 新建 $ docker create -it ubuntut:latest $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9f0fec4d4b05 ubuntu:latest "/bin/bash" 42 seconds ago Created strange_austin 啟動 用 create 新建的容器處於停止狀態 docker start 啟動 docker start 9f0fec4d4b05 $ docker ps # 查看正在執行的容器 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9f0fec4d4b05 ubuntu:latest "/bin/bash" 5 minutes ago Up 2 minutes strange_austin 建立並啟動 docker run docker run ubuntu /bin/echo "hello, world" 輸出 hello, world 容器便終止 檢查本機是否存在指定的 image,不存在就從公開的倉庫下載 利用 image 建立 container 並啟動 container ( docker create + docker start ) 分配檔案系統給容器...

程式語言初學者 Docker 入門第三章 —— 映像檔 Image

Docker 執行容器前需要本地端具備相對應的映像檔,如果映像檔未存在本地端,Docker 會嘗試先從預設映像檔倉庫下載,使用者也可以透過設定,使用自訂的映像檔倉庫 取得映像檔 可以在 Docker Hub 找到相對應的 images docker pull NAME[:TAG] NAME 是映像檔倉庫名稱; TAG 是映像檔的標籤(通常用來表示版本資訊,不寫就是預設:latest) 官方的 image 在 pull 時可以不寫 registry $ docker pull ubuntu # 完整指令 $ docker pull registry.hub.docker.com/ubuntu:14.04 registry(倉庫位址 docker hub IP): registry.hub.docker.com/ >>> Using default tag: latest latest: Pulling from library/ubuntu Digest: sha256:adf73ca014822ad8237623d388cedf4d5346aa72c270c5acc01431cc93e18e2d Status: Image is up to date for ubuntu:latest docker.io/library/ubuntu:latest 非官方的 image 要寫 registry docker pull gcr.io/tensorflow/tensorflow:latest-gpu Google Container Registry: gcr.io/tensorflow/tensorflow -a, —all-tags=true|false:是否取得倉庫中的所有標籤之映像檔,default = false 實戰 取得映像檔  pull image 拉取 postgres images ╰─$ docker pull postgres 拉取 ubuntu image ╰─$ docker pull ubuntu 查看 image 映像檔訊息 docker images 指令 ╰─$ docker images REPOSITORY TAG IMAGE ID CREATED ...

程式語言初學者 Docker 入門第二章 —— 安裝與驗證 (Mac)

Image
驗證 Docker 安裝 這邊介紹兩種安裝方式 Docker Desktop 簡單好用、好理解、易上手,請至底下連結到官網安裝 Docker Desktop for Mac and Windows | Docker 安裝完成後,可以在 Terminal 終端機下以下 command $ docker version 如果看到類似的  error message   Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? 表示沒有正常啟動,去 Application 把 Docker 打開 以下為正常顯示 Client: Cloud integration: 1.0 .14 Version: 20.10 .6 API version: 1.41 Go version: go1.16.3 Git commit: 370c289 Built: Fri Apr 9 22 : 46 : 57 2021 OS/Arch: darwin/amd64 Context: default Experimental: true Server: Docker Engine - Community Engine: Version: 20.10 .6 API version: 1.41 (minimum version 1.12 ) Go version: go1.13.15 Git commit: 8728dd2 Built: Fri Apr 9 22 : 44 : 56 2021 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.4 .4 GitCommit: 05f951a3781f4f2c1911b05e61c160e9c...

程式語言初學者 Docker 入門第一章 —— 簡介

Image
用 Docker 的好處簡單來說就是 Build, Ship and Run Any App Anywhere 你可以在任何地方搭建、遷移、執行你的 App 是不是聽起來很方便!( 大致上) 不受機器限制,不用裝討人厭的環境! 起源 Virtual Machine (VM)  虛擬機起源 我想要在同一台電腦上運行不同作業系統,虛擬機用來解決這個問題 。 Virtual machines were originally designed to allow multiple operating systems to run on a single physical machine. The objective is to allow users to create a virtual environment that’s isolated from the underlying hardware. VMs abstract hardware details to make it easier to run applications on different hardware architectures and use hardware resources more efficiently. 虛擬機器 最初設計的目的是允許多個作業系統在單一實體機上運行。目標是允許使用者建立與底層硬體隔離的虛擬環境。虛擬機器抽象化了硬體細節,以便更輕鬆地在不同硬體架構上運行應用程式並更有效地使用硬體資源。 Docker 起源 我想要在同個作業系統上運行多個應用程式,Docker 透過容器化 (containerize) 解決了這個問題。 Docker was designed to provide a lightweight and portable way to package and run applications in an isolated and reproducible environment. Docker abstracts operating system details to address the challenge of deploying applications across different environments, such as develo...