docker 安装以及简单使用

1.安装docker

docker是在Ubuntu上开发的最合适安装在Ubuntu系统上

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

运行

sudo docker service start

验证

root@suntang:~# 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:

https://docs.docker.com/engine/userguide/

2.运行运行docker镜像

root@suntang:~# docker run -it -d --name centostest centos

参数说明

-it 命令交互模式启动

-d 后台运行

--name 容器命名

centos 镜像名称

-p 端口映射(本机端口:容器端口)

-v 文件映射(本机文件目录:容器文件目录)

3.进入容器

root@suntang:~# docker exec -it 611e84095181(容器id) /bin/bash

[root@611e84095181 /]#

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

root@suntang:~# 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

查看位置

root@suntang:/# 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"

}

]

8.主机与虚拟机文件拷贝

docker cp /root/test (本机文件路径) a2d9366fdd08:/root/(容器id:容器路径)

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值