1. 程式人生 > >docker 安裝以及簡單使用

docker 安裝以及簡單使用

1.安裝docker

docker是在Ubuntu上開發的最合適安裝在Ubuntu系統上

wget -qO- https://get.docker.com/ | sh

執行

sudo docker service start

驗證

[email protected]:~# docker run hello-world

Hello from Docker!

This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:

1. The Docker client contacted the Docker daemon.

2. The Docker daemon pulled the "hello-world" image from the Docker Hub.

(amd64)

3. The Docker daemon created a new container from that image which runs the

executable that produces the output you are currently reading.

4. The Docker daemon streamed that output to the Docker client, which sent it

to your terminal.

To try something more ambitious, you can run an Ubuntu container with:

$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:

https://hub.docker.com/

For more examples and ideas, visit:

2.執行執行docker映象

[email protected]:~# docker run -it -d --name centostest centos

引數說明

-it 命令互動模式啟動

-d 後臺執行

--name 容器命名

centos 映象名稱

-p 埠對映(本機埠:容器埠)

-v 檔案對映(本機檔案目錄:容器檔案目錄)

3.進入容器

[email protected]:~# docker exec -it 611e84095181(容器id) /bin/bash

[[email protected] /]#

4.刪除容器

docker rm 611e84095181(容器id)

docker rmi (刪除映象)

5.檢視容器

docker ps -a 檢視所有容器

docker stats 檢視正在執行的容器

6.dokcer提交映象(提交到本地)

docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

OPTIONS說明:

  • -a :提交的映象作者;
  • -c :使用Dockerfile指令來建立映象;
  • -m :提交時的說明文字;
  • -p :在commit時,將容器暫停。

例項

將容器a2d9366fdd08儲存為新的映象,並新增提交人資訊和說明資訊。

docker commit -a 'zhaox' -m 'lnmp' a2d9366fdd08

[email protected]:~# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

<none> <none> 95e5a41a9a4a 50 seconds ago 3.23GB

mysql 5.6 1f47fade220d 7 hours ago 256MB

6.映象重新命名

docker tag IMAGEID(映象id) REPOSITORY:TAG(倉庫:標籤) #例子 docker tag a2d9366fdd08 lnmp:v1.0

7.docker volume

建立

docker volume create --name vol_simple

掛載

docker run -it -v vol_simple:/home ubuntu /bin/bash

檢視位置

[email protected]:/# docker volume inspect vol_simple

[

{

"CreatedAt": "2018-09-06T07:31:23Z",

"Driver": "local",

"Labels": {},

"Mountpoint": "/var/lib/docker/volumes/vol_simple/_data",

"Name": "vol_simple",

"Options": {},

"Scope": "local"

}

]