1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【docker】docker試煉日(1)基礎介紹

Last updated at Posted at 2020-02-08

#目的
熟悉與掌握docker用法,實作出內部測試環境與降低多環境需求之成本

#Docker 架構
Docker 包括三個基本元素:

  • 鏡像(Image):Docker 鏡像(Image),就相當於是一個 root 文件系統。比如官方鏡像 ubuntu:16.04 就包含了完整的一套 Ubuntu16.04 最小系統的 root 文件系統。
  • 容器(Container):鏡像(Image)和容器(Container)的關係,就像是VM安裝概念一樣,鏡像是靜態的定義,容器是鏡像運行時的實體。容器可以被創建、啟動、停止、刪除、暫停等,隨時可依據需求啟動一個你所需要的容器(Ubuntu CentOS等)。
  • 倉庫(Repository):倉庫可視為一個程式碼控制中心,用來保存鏡像。
    Docker 使用客戶端-服務器 (C/S) 架構模式,使用遠端API來管理和創建Docker容器。

Docker 容器通過 Docker 鏡像來創建。

576507-docker1.png

#安裝方法
https://www.runoob.com/docker/centos-docker-install.html

#起手式
當安裝完成docker 都要先來跑跑看是否已經能正常運行
接下來我們就開始運行我們的第一個Docker吧

P-MP15:~ puwu$ docker run ubuntu:15.10 /bin/echo "Hello world"
Unable to find image 'ubuntu:15.10' locally
15.10: Pulling from library/ubuntu
7dcf5a444392: Pull complete
759aa75f3cee: Pull complete
3fa871dc8a2b: Pull complete
224c42ae46e7: Pull complete
Digest: sha256:02521a2d079595241c6793b2044f02eecf294034f31d6e235ac4b2b54ffc41f3
Status: Downloaded newer image for ubuntu:15.10
Hello world

好的,我們今天終於完成第一項任務,可以讓我的使用docker 幫我們印出Hello world
這是多麼不容易的事情(?)

接下來讓我們了解一下啟動時參數使用的用途

使用docker鏡像nginx:latest以後台模式啟動一个容器,并將容器命名為mynginx。

docker run --name mynginx -d nginx:latest  

使用鏡像nginx:latest以後臺模式啟動壹個容器,將容器的80端口映射到主機的80端口,主機的目錄/data映射到容器的/data

docker run -p 80:80 -v /data:/data -d nginx:latest  

使用鏡像nginx:latest以互動模式啟動一個容器,在容器內執行/bin/bash命令。

P-MP15:~ puwu$ docker run -it nginx:latest /bin/bash
root@fecf799928e4:/# 

進入啟動中的容器243c32535da7,使用這個即使下了exit 也不會中斷服務

docker exec -it 243c32535da7 /bin/bash

更多詳細的參數可以參考HERE

背景服務與操作可參考這篇(後續再補上)HERE

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?