1、dockers 镜像、容器、仓库
2、
在centos和redhat上安装docker
前置条件
- 64-bit 系统
- kernel 3.10+
1.检查内核版本,返回的值大于3.10即可。
$ uname -r
2.使用 sudo 或 root 权限的用户登入终端。
3.确保yum是最新的
$ yum update
4.添加 yum 仓库
$ tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
5.安装 Docker
$ yum install -y docker-engine
6.启动docker
$ systemctl start docker.service
7.验证安装是否成功(有client和service两部分表示docker安装启动都成功了)
M:~$docker version
Client:
Version: 1.13.1
API version: 1.26
Go version: go1.7.5
Git commit: 092cba3
Built: Wed Feb 8 08:47:51 2017
OS/Arch: darwin/amd64
Server:
Version: 1.13.1
API version: 1.26 (minimum version 1.12)
Go version: go1.7.5
Git commit: 092cba3
Built: Wed Feb 8 08:47:51 2017
OS/Arch: linux/amd64
Experimental: true
作者:
刘果国
前置条件
- 64-bit 系统
- kernel 3.10+
1.检查内核版本,返回的值大于3.10即可。
$ uname -r
2.使用 sudo 或 root 权限的用户登入终端。
3.确保yum是最新的
$ yum update
4.添加 yum 仓库
$ tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo] name=Docker
Repository baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg EOF
5.安装 Docker
$ yum install -y docker-engine
6.启动docker
$ systemctl start docker.service
7.验证安装是否成功(有client和service两部分表示docker安装启动都成功了)
M:~$docker version
8、第一个docker 镜像Hello Wolrd!
docker pull [OPTIONS] NAME[:TAG]
拉去镜像文件用
docker images [OPTIONS] [REPOSITORY] [:TAG]
查看本地的镜像
下面是下载第一个镜像
[root@dev3 /]# docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
5b0f327be733: Pull complete
Digest: sha256:1f19634d26995c320618d94e6f29c09c6589d5df3c063287a00e6de8458f8242
Status: Downloaded newer image for hello-world:latest
[root@dev3 /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 05a3bd381fc2 8 days ago 1.84kB
9、第一个docker容器的运行
dockers [OPTIONS] IMAGE[:TAG] [COMMAND][ARG...] 运行容器的命令
实例:
[root@dev3 /]# 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.
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:
docker下载镜像的原理图
10、实战:docker下面运行nginx
下载nginx的镜像https://c.163.com/hub#/m/search/?keyword=nginx用带鲸鱼图标的镜像,这样的镜像是docker官网同步的。
拷贝下载地址:
docker pull hub.c.163.com/library/nginx:latest
REPOSITORY TAG IMAGE ID CREATED SIZE
hub.c.163.com/library/nginx latest 46102226f2fd 4 months ago 109MB
查看容器的运行状态
docker ps -a
在后台运行nginx
[root@dev3 /]# docker run -d hub.c.163.com/library/nginx
ad51e2088b0fa38410fb31682b57cd1ac4f0ca0dfdaf0e6b06a0216f971d7413
显示运行成功用上面的命令可以查看
root@dev3 /]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ad51e2088b0f hub.c.163.com/library/nginx "nginx -g 'daemon ..." 39 seconds ago Up 38 seconds 80/tcp vigorous_bell
进入容器查看容器日志,出现下面红色位置就显示进入到容器了。
[root@dev3 /]# docker exec -it ad51e2088b0f bash
root@ad51e2088b0f:/#
退出容器
root@ad51e2088b0f:/# exit
exit
停止容器
[root@dev3 /]# docker stop ad51e2088b0f
ad51e2088b0f
重启容器
docker restart 容器ID
11、docker网络
网络类型
Bridge HOST
端口映射本地端口对应容器端口
外部访问容器里面的Nginx
docker run --help
查看命令
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
[root@dev3 /]# docker run -d -p 9500:80 hub.c.163.com/library/nginx
2c88ac8276f2f1fa7555c0799294ca3ba4dff768fe36dddff8c558040d5728a7
映射对应的端口查看运行结果:
[root@dev3 /]# docker run -d -P 9500:80 hub.c.163.com/library/nginx
用-P是随机开放一个端口
12、制作自己的镜像
Dockerfile 创建镜像文件
dockers build 创建镜像
jpress 下载网站war包http://jpress.io/
包名 jpress.war
1、下载一个tomcat镜像
docker pull hub.c.163.com/library/tomcat:latest
[root@dev3 imooc]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hub.c.163.com/library/tomcat latest 72d2be374029 6 weeks ago 292MB
2、Dockerfile的内容
from hub.c.163.com/library/tomcat
MAINTAINER test test@163.com
COPY jpress.war /usr/local/tomcat/webapps 把应用拷贝到容器里面,这个地址查询https://c.163.com/hub#/m/repository/?repoId=3105,可以看到容器信息和端口。
3、建立镜像
docker build -t jpress:latest . 建立当前目录的位置,名字jpress 标签:latest
13、建立mysql镜像
docker pull hub.c.163.com/library/mysql:latest
启动查看命令同上,
前置条件
- 64-bit 系统
- kernel 3.10+
1.检查内核版本,返回的值大于3.10即可。
$ uname -r
2.使用 sudo 或 root 权限的用户登入终端。
3.确保yum是最新的
$ yum update
4.添加 yum 仓库
$ tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
5.安装 Docker
$ yum install -y docker-engine
6.启动docker
$ systemctl start docker.service
7.验证安装是否成功(有client和service两部分表示docker安装启动都成功了)
M:~$docker version
Client:
Version: 1.13.1
API version: 1.26
Go version: go1.7.5
Git commit: 092cba3
Built: Wed Feb 8 08:47:51 2017
OS/Arch: darwin/amd64
Server:
Version: 1.13.1
API version: 1.26 (minimum version 1.12)
Go version: go1.7.5
Git commit: 092cba3
Built: Wed Feb 8 08:47:51 2017
OS/Arch: linux/amd64
Experimental: true
作者: 刘果国