docker 使用


1.安装

mac 安装 docker

1.点击下载安装包,安装完后查看版本

lphdeMacBook-Pro:~ lph$ docker -v
Docker version 1.12.3, build 6b644ec   

2.由于国内用户访问 Docker Hub 缓慢的问题,所以这边我们用DaoCloud 加速器.

  a.注册DaoCloud 获取 专属镜像加速器

  b.安装官网提示添加 加速器

  c.运行加速器是否有效 , 一下表明加速器配置成功!

lphdeMacBook-Pro:etc lph$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9bb5a5d4561a: Pull complete 
Digest: sha256:d5c74e6f8efc7bdf42a5e22bd764400692cf82360d86b8c587a7584b03f51520
Status: Downloaded newer image for hello-world:latest

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/

ubuntu 安装 docker

Docker 要求 Ubuntu 系统的内核版本高于 3.10 ,所以需要先查看ubuntu内核

$ uname -r
4.4.0-93-generic

获取最新版本 docker安装包

$ wget -qO- https://get.docker.com/ | sh
.....
adding your user to the "docker" group with something like:

  sudo usermod -aG docker your-user

Remember that you will have to log out and back in for this to take effect!
....

安装中 提醒 sudo usermod -aG docker your-user 需要管理员 运行docker,所以这边把你的用户名加入docker组中

$ sudo usermod -aG docker your-user(你的用户名)

如果你是天朝用户而且下载镜像特别慢 请 点此查看换源

2.第一次运行docker 应用

lphdeMacBook-Pro:etc lph$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9bb5a5d4561a: Pulling fs layer 
docker: error pulling image configuration: Get https://dseasb33srnrn.cloudfront.net/registry-v2/docker/registry/v2/blobs/sha256/e3/e38bc07ac18ee64e6d59cf2eafcdddf9cec2364dfe129fe0af75f1b0194e0c96/data?Expires=1523730106&Signature=jsNgoIZ~0pweOgs-6h-w9TLd7EdMWjHXfJW7ZBNSKSLZySzO3NhpfGYZ-MKpiTwvFmcwjd~Yh4CUZu7Mq7oWxZoGyCCXNm1dAUD8-DADlledaqFRFrdmxy8D5-39Wa03uREnNCPSf~AKxjbrNlE-QsySL3q~BI15jjtQ2~di0vo_&Key-Pair-Id=APKAJECH5M7VWIS5YZ6Q: net/http: TLS handshake timeout.
See 'docker run --help'.

2.docker使用

首先

docker的使用教程很多这里就不一一介绍,需要看docker使用请点击跳转,这边列出常用的指令

$ docker pull ubuntu:14.04 #安装ubuntu14 镜像
$ docker run -i -t  ubuntu:14.04 /bin/bash #运行ubuntu脚本
$ docker ps #查看运行中的镜像
$ docker stop ID #停止镜像
$ docker rm $(docker ps -a -q) #清除所有容器
$ docker rmi $(docker images) #清除所有镜像
$ docker rmi -f ID #强制删除
$ docker images #显示镜像列表
$ docker rmi ID #删除镜像ID为镜像ID

docker compose 安装

mac安装:

执行安装命令:

# curl -L https://github.com/docker/compose/releases/download/1.7.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

安裝完畢之後我們需要給予 Docker Compose 一定的執行權限。

$ chmod +x /usr/local/bin/docker-compose

接著我們就可以透過 docker-compose --version 檢查剛才安裝的 Docker 

ubuntu安装:

$ apt install docker-compose
$ docker-compose -v

猜你喜欢

转载自my.oschina.net/oslph/blog/1796083