Docker环境搭建

 

一。 Linux下安装

  1. 查看版本uname -r
$uname -r
4.13.0-36-generic
hadoop@zhu0129:~$ 

    2. 安装Docker    wget -qO- https://get.docker.com/ | sh

root@ubuntu:~# wget -qO- https://get.docker.com/ | sh
# Executing docker install script, commit: 02d7c3c
+ sh -c apt-get update -qq >/dev/null
+ sh -c apt-get install -y -qq apt-transport-https ca-certificates curl >/dev/null
+ sh -c curl -fsSL "https://download.docker.com/linux/ubuntu/gpg" | apt-key add -qq - >/dev/null
+ sh -c echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial edge" > /etc/apt/sources.list.d/docker.list
+ [ ubuntu = debian ]
+ sh -c apt-get update -qq >/dev/null
+ sh -c apt-get install -y -qq --no-install-recommends docker-ce >/dev/null


+ sh -c docker version
Client:
 Version:	18.03.0-ce
 API version:	1.37
 Go version:	go1.9.4
 Git commit:	0520e24
 Built:	Wed Mar 21 23:10:01 2018
 OS/Arch:	linux/amd64
 Experimental:	false
 Orchestrator:	swarm

Server:
 Engine:
  Version:	18.03.0-ce
  API version:	1.37 (minimum version 1.12)
  Go version:	go1.9.4
  Git commit:	0520e24
  Built:	Wed Mar 21 23:08:31 2018
  OS/Arch:	linux/amd64
  Experimental:	false
If you would like to use Docker as a non-root user, you should now consider
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!

WARNING: Adding a user to the "docker" group will grant the ability to run
         containers which can be used to obtain root privileges on the
         docker host.
         Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
         for more information.
root@zhu0129:~# 

which wget 
如果没有安装,使用 
sudo apt-get update 
sudo apt-get install wget 

 

3.  启动docker后台服务

 sudo service docker start

 

4.  测试运行 sudo docker run hello-world

hadoop@ubuntu:~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete 
Digest: sha256:97ce6fa4b6cdc0790cda65fe7290b74cfebd9fa0c9b8c38e979330d547d22ce1
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://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

hadoop@zhu0129:~$ 

 

5.  镜像加速

 

二。 centos7

1.   uname -r 查看 centos内核版本  需在3.20以上

2.  sudo yum update更新

3.  安装docker

yum -y install docker

 

4.  启动docker后台服务

service docker start

5.  测试运行hello-word

docker run hello-world

6. 一般拉取镜像十分缓慢,所以我们需要配置加速器

[root@zhumaster ~]# cd /etc/docker/
[root@zhumaster docker]# ls
certs.d  daemon.json  key.json  seccomp.json
[root@zhumaster docker]# vim daemon.json 

在json文件中添加加速器。 

{
 "registry-mirrors": ["http://hub-mirror.c.163.com"]
}

 

 

posted @ 2018-03-20 00:00  appointint  阅读(185)  评论(0编辑  收藏  举报