赞
踩
目录
一.Docker整体介绍
二.网络模式介绍
三.docker安装
四.docker镜像操作
五.docker容器操作
六.容器设置固定IP
七.Dockerfile制作镜像
八.shipyard的安装使用
九.抢购网基础服务环境
十.分布式ID微服务案例
错误
Docker是什么?
Docker是一个基于LXC(linux container)技术构建的容器引擎,基于GO语言开发,遵循Apache2.0协议开源。https://c.163yun.com/hub#/m/home/
运行环境
Docker daemon是核心。
网络配置:
host模式,
container模式
none模式
bridge模式,默认
--net=(具体模式名称)
端口映射
-p
host模式:和当前的宿主机公用一个模式。会把本机的ip和端口暴露出去。
container模式:和现在一个存在的容器公用一个模式。
none模式:不会给容器进行任何的网络配置。
brige模式:给Docker容器分配一个没有占用的ip,并且ip是逐渐递增的。所以要设置一个固定ip.
--net=(具体模式名称)
Docker容器是不能直接被外部访问的。需要“端口映射”,把Docker容器的端口号映射到宿主机的端口号上去。
Ubuntu(16.04.3)
安装本地版本:apt-get install -y docker.io
启动服务:(sudo) service docker start
查看版本:docker --version|docker -v
查看镜像:docker images
docker,可以在ubuntu,centos等都可以用,但是docker是在ubuntu系统开发的。
ubuntu镜像列表:http://releases.ubuntu.com/
ubuntu下载镜像:http://releases.ubuntu.com/16.04.3/ubuntu-16.04.3-desktop-amd64.iso
查看镜像
docker images
搜索镜像
docker search 镜像关键字
镜像拉取
docker pull [OPTIONS] NAME[:TAG|@DIGEST]
镜像删除
docker rmi 镜像ID或镜像名称
生产容器
docker run -d -p 8888:8080 --name tomcat-test tomcat
说明:-d:后台运行 -p:端口映射 8888:宿主机端口.8080:docker容器端口,tomcat-test:容器名字,tomcat:镜像名称
查看容器(查看正在运行的容器)
docker ps|grep 容器关键字
查询全部(包括已停止)的容器
docker ps -a|grep 容器关键字
进入容器
docker exec -it containerId/containerName /bin/bash
退出容器
exit
停止容器
docker stop containerId/containerName
启动容器
docker start containerId/containerName
删除容器
docker rm containerId/containerName
拷贝文件
docker cp 宿主机目录及文件 容器名称:容器目录
问题1:删除images的时候报错,因为安装的时候,安装一半就断开了。
docker@ubuntu:~$ docker rmi registry.cn-beijing.aliyuncs.com/wz-web/sd-tomcat
Error response from daemon: conflict: unable to remove repository reference "registry.cn-beijing.aliyuncs.com/wz-web/sd-tomcat" (must force) - container af06eabfa3bb is using its referenced image ba886ec36feciej
解决方法:
docker@ubuntu:~$ su
Password:
root@ubuntu:/home/docker# docker ps -a -q
af06eabfa3bb
root@ubuntu:/home/docker# docker stop af06eabfa3bb
af06eabfa3bb
root@ubuntu:/home/docker# docker rm af06eabfa3bb
af06eabfa3bb
root@ubuntu:/home/docker# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.cn-beijing.aliyuncs.com/wz-web/sd-tomcat latest ba886ec36fec 15 months ago 1.62 GB
root@ubuntu:/home/docker# docker rmi registry.cn-beijing.aliyuncs.com/wz-web/sd-tomcat
Untagged: registry.cn-beijing.aliyuncs.com/wz-web/sd-tomcat:latest
Untagged: registry.cn-beijing.aliyuncs.com/wz-web/sd-tomcat@sha256:07407903b9b0ad615e35cc2f74ec570f12fc5e07d537e94621e6a61af95bb4b3
Deleted: sha256:ba886ec36feca1e87a0a8759c747a3d7dc52c23a75e57a058c36fc1cd997f035
Deleted: sha256:322ec6b0d87ffe503f64d925d7f695b4dfce785fb4976e45b09bb60a08b3c7a8
Deleted: sha256:a2555195370c93c4c0ed29c9a13d41ff66bfc6e1f9497c75d38ab0e709909b30
Deleted: sha256:7e8cadda0ed98db3e14da46c262ee0cfd454ede3a7014504e253ac0efff983f9
Deleted: sha256:e4f419aa3bb7c651b67ff5b0a73ae877a9ff69bbcd6decd827fe23e99e80b01c
Deleted: sha256:7617e3308501bd74d523b0c5e78d6dfbc1ff5c550ababc3eec10bb2e53905e70
Deleted: sha256:63bb6ec16d29c354ed3727f7e360f4faf16be05491a74fc43985401c0f14e673
Deleted: sha256:7dd7cc9d1211eb2471fb16495ac9195a6e19bbae9ecf912192990e419411bfbb
Deleted: sha256:f53363a03aeec7db332a01cb264f7d32dbbd87ae932cd19fb4616398be491466
Deleted: sha256:d3970dfaee6b2aaf226a77d86e4ce9cf09ec3a65e589d27e4b10fe8fbb6d052a
Deleted: sha256:c65efa9d7f8eda11ad10c43f4a180bd22a8c61d22dd57d3762a96da201e72006
Deleted: sha256:05995dcff1cf0e43667deed015ace7826e1c760d9431bf29c3e4bbc52b0a704d
Deleted: sha256:6066b2e1f7903d09fb3e05b4d35e7abd91fe611783dc9a5af5bad8baf3233fe9
Deleted: sha256:6b9579911da3d8a74d8edf7ada2f9d7097da14df4e0b5bf649e6d72eda43254e
Deleted: sha256:665ce5f28f2322479bed3de104d9c3fa013825a4ce70fc3396b5bde34b5392cc
Deleted: sha256:b4a701bfd9ca01c5e4630efd43760d5b08e654a9aef34d0139ef321286c2c140
Deleted: sha256:1fc168e7266935f9a2cf1dfef801bfba35510976e935d42e628dfc4416b502a3
Deleted: sha256:7856a80edcb0dc7d4ee9a661314574b305c846dbb78b1b152d1bef4a2e1abbbe
Deleted: sha256:8bf1b112864e2427399eaafa065c77a1540cb4a4842e13cbc062c4a907081223
Deleted: sha256:508320815c211e2c8e01724de25ceb2b1c9d4bdde98b5aa16941bac8957885d9
Deleted: sha256:e52f47defd901ee2e5359fa31cf9d3ea6e1862f8805ac4bfbf7b5f64b40d6404
Deleted: sha256:d73c31c5daa6dd0f708bb547d48d103b63004fa8365515a0e40b4af620347148
r
su | q切换到root |
docker ps -a -q | docker ps:列出容器 ; -a:所有容器; -q:静默模式,只显示容器编号 |
docker stop af06eabfa3bb | 停止一个运行中的容器 |
docker rm af06eabfa3bb | 删除一个容器 |
docker images | 列出本地镜像 |
docker rmi registry.cn-beijing.aliyuncs.com/wz-web/sd-tomcat | 删除镜像 |
root@ubuntu:/home/docker# docker pull registry.cn-hangzhou.aliyuncs.com/shuodao/tomcat-8.5.27
Using default tag: latest
latest: Pulling from shuodao/tomcat-8.5.27
8f7c85c2269a: Pull complete
9e72e494a6dd: Pull complete
3009ec50c887: Pull complete
9d5ffccbec91: Pull complete
e872a2642ce1: Pull complete
558a041b7256: Pull complete
5bd2d92394a5: Pull complete
Digest: sha256:05fa942790b8d42bfd4f5a16527609c9e9ddb4a45a04a8d31e5750c3a2b7c1bd
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/shuodao/tomcat-8.5.27:latest
root@ubuntu:/home/docker# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.cn-hangzhou.aliyuncs.com/shuodao/tomcat-8.5.27 latest d07ca8aba782 2 months ago 369 MB
root@ubuntu:/home/docker# docker run -d -p 8888:8080 --name mytomcat registry.cn-hangzhou.aliyuncs.com/shuodao/tomcat-8.5.27
8e195d1630b7875b1ab2fde17b4cba1a7bc407d70c332b021d18eb16662ec066
root@ubuntu:/home/docker# docker exec -it mytomcat /bin/bash
root@8e195d1630b7:/# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
root@8e195d1630b7:/# cd usr
root@8e195d1630b7:/usr# ls
bin games include java lib local sbin share src tomcat
root@8e195d1630b7:/usr# exit
exit
root@ubuntu:/home/docker#
效果:在虚拟机上面打开网页,输入地址http://localhost:8888可以访问到tomcat页面
停止容器
docker@ubuntu:~$ docker stop mytomcat
mytomcat
访问地址,访问不到。
删除容器
docker@ubuntu:~$ docker rm mytomcat
mytomcat
docker@ubuntu:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
docker@ubuntu:~$
编辑好一个文件bg.html。拖动文件到虚拟机的桌面上面(/home/docker/Desktop),复制文件到容器上面,
docker@ubuntu:~$ docker cp /home/docker/Desktop/bg.html mytomcat:/usr/tomcat/webapps/ROOT
浏览器中输入地址http://localhost:8888/bg.html,可以访问
六.容器设置固定IP
动态IP
固定IP
创建网络,指定网段
docker network create --subnet=172.18.0.0/16 mynetwork
创建容器,指定IP
docker run -it -d --net mynetwork --ip 172.18.0.8 --name mytomcat tomcat
问题:默认是bridge模式,ip是递增的。但是问题是,如果使用命令stop,start。停止,启动容器,ip地址和启动容器的顺序有关系。不能保证每次容器的启动顺序一样。
docker@ubuntu:~$ docker stop mytomcat
mytomcat
docker@ubuntu:~$ docker rm mytomcat
mytomcat
docker@ubuntu:~$ ifconfig
docker0 Link encap:Ethernet HWaddr 02:42:b0:b3:09:90
inet addr:172.17.0.1 Bcast:0.0.0.0 Mask:255.255.0.0
inet6 addr: fe80::42:b0ff:feb3:990/64 Scope:Link
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:138 errors:0 dropped:0 overruns:0 frame:0
TX packets:171 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:110567 (110.5 KB) TX bytes:17715 (17.7 KB)
ens33 Link encap:Ethernet HWaddr 00:0c:29:5e:53:19
inet addr:192.168.117.129 Bcast:192.168.117.255 Mask:255.255.255.0
inet6 addr: fe80::5c08:ab11:d26f:72cf/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:798535 errors:0 dropped:0 overruns:0 frame:0
TX packets:129664 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1087812256 (1.0 GB) TX bytes:7990259 (7.9 MB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:2021 errors:0 dropped:0 overruns:0 frame:0
TX packets:2021 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:288241 (288.2 KB) TX bytes:288241 (288.2 KB)
docker@ubuntu:~$ docker run -d --name tomcat1 registry.cn-hangzhou.aliyuncs.com/shuodao/tomcat-8.5.27
6be03a058fff220860414f4f10c4eb306bc42efec65e782dca7e95f956f64e56
docker@ubuntu:~$ docker run -d --name tomcat2 registry.cn-hangzhou.aliyuncs.com/shuodao/tomcat-8.5.27
2ac375d795b7950a12c91025b6bb4f0abfff31edb5dc71137f059bd1f90f1253
docker@ubuntu:~$ docker run -d --name tomcat3 registry.cn-hangzhou.aliyuncs.com/shuodao/tomcat-8.5.27
7bdb86f533648670bc981c1f5ded051b1209378ed8788a2ae8a3ff273e26ec48
docker@ubuntu:~$ docker inspect 6be03a058fff220860414f4f10c4eb306bc42efec65e782dca7e95f956f64e56
[
{
"Id": "6be03a058fff220860414f4f10c4eb306bc42efec65e782dca7e95f956f64e56",
"Created": "2018-05-19T02:31:54.115185904Z",
"Path": "/bin/sh",
"Args": [
"-c",
"/usr/tomcat/bin/startup.sh \u0026\u0026 tail -f /usr/tomcat/logs/catalina.out"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 5272,
"ExitCode": 0,
"Error": "",
"StartedAt": "2018-05-19T02:31:55.925554617Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:d07ca8aba782970b40ace62885f818d3871dd6d37d35a63c1963189e5c5b3cc4",
"ResolvConfPath": "/var/lib/docker/containers/6be03a058fff220860414f4f10c4eb306bc42efec65e782dca7e95f956f64e56/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/6be03a058fff220860414f4f10c4eb306bc42efec65e782dca7e95f956f64e56/hostname",
"HostsPath": "/var/lib/docker/containers/6be03a058fff220860414f4f10c4eb306bc42efec65e782dca7e95f956f64e56/hosts",
"LogPath": "/var/lib/docker/containers/6be03a058fff220860414f4f10c4eb306bc42efec65e782dca7e95f956f64e56/6be03a058fff220860414f4f10c4eb306bc42efec65e782dca7e95f956f64e56-json.log",
"Name": "/tomcat1",
"RestartCount": 0,
"Driver": "aufs",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": -1,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0
},
"GraphDriver": {
"Name": "aufs",
"Data": null
},
"Mounts": [],
"Config": {
"Hostname": "6be03a058fff",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"8080/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/java/bin:/usr/tomcat/bin",
"JAVA_HOME=/usr/java",
"CATALINA_HOME=/usr/tomcat"
],
"Cmd": null,
"ArgsEscaped": true,
"Image": "registry.cn-hangzhou.aliyuncs.com/shuodao/tomcat-8.5.27",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": [
"/bin/sh",
"-c",
"/usr/tomcat/bin/startup.sh \u0026\u0026 tail -f /usr/tomcat/logs/catalina.out"
],
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "a99ce7622514d0cd54052bb04facec857888ef1bc71e262d804effe97d0df405",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"8080/tcp": null
},
"SandboxKey": "/var/run/docker/netns/a99ce7622514",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "b53595fa6a3d18b7e78c3ed5442bd5a293b91e46d6c9d2c3f049a1f918295812",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "2428d0d534bc576f3088f1e5bdeb43e33fb93eafe36edc9711f318635e9a0d33",
"EndpointID": "b53595fa6a3d18b7e78c3ed5442bd5a293b91e46d6c9d2c3f049a1f918295812",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02"
}
}
}
}
]
docker@ubuntu:~$ docker inspect --format='{<!-- -->{.Name}} - {<!-- -->{range .NetworkSettings.Networks}}{<!-- -->{.IPAddress}}{<!-- -->{end}}' $(docker ps -aq)
/tomcat3 - 172.17.0.4
/tomcat2 - 172.17.0.3
/tomcat1 - 172.17.0.2
docker@ubuntu:~$ docker stop tomcat1
tomcat1
docker@ubuntu:~$ docker stop tomcat2
tomcat2
docker@ubuntu:~$ docker stop tomcat3
tomcat3
docker@ubuntu:~$ docker start tomcat3
tomcat3
docker@ubuntu:~$ docker start tomcat2
tomcat2
docker@ubuntu:~$ docker start tomcat1
tomcat1
docker@ubuntu:~$ docker inspect --format='{<!-- -->{.Name}} - {<!-- -->{range .NetworkSettings.Networks}}{<!-- -->{.IPAddress}}{<!-- -->{end}}' $(docker ps -aq)
/tomcat3 - 172.17.0.2
/tomcat2 - 172.17.0.3
/tomcat1 - 172.17.0.4
docker@ubuntu:~$
docker inspect : 获取容器/镜像的元数据。
给容器分配固定ip
docker@ubuntu:~$ docker network create --subnet=172.18.0.0/16 aynetwork
f4acbd0bb4ddcba987515bc471c9ad9a400417bca44e963aad6e5a034be4007e
docker@ubuntu:~$ docker run -d -it --net aynetwork --ip 172.18.0.8 --name tomcat5 registry.cn-hangzhou.aliyuncs.com/shuodao/tomcat-8.5.27
b0ae82655a3af6183a7836867282ee5931d0d085bf5356145b77de4f515e914c
docker@ubuntu:~$ docker inspect --format='{<!-- -->{.Name}} - {<!-- -->{range .NetworkSettings.Networks}}{<!-- -->{.IPAddress}}{<!-- -->{end}}' $(docker ps -aq)
/tomcat5 - 172.18.0.8
/tomcat4 -
/tomcat3 -
/tomcat2 -
/tomcat1 -
docker@ubuntu:~$ docker stop tomcat5
tomcat5
docker@ubuntu:~$ docker start tomcat5
tomcat5
docker@ubuntu:~$ docker inspect --format='{<!-- -->{.Name}} - {<!-- -->{range .NetworkSettings.Networks}}{<!-- -->{.IPAddress}}{<!-- -->{end}}' $(docker ps -aq)
/tomcat5 - 172.18.0.8
/tomcat4 -
/tomcat3 -
/tomcat2 -
/tomcat1 -
docker@ubuntu:~$
内置命令
FROM:依赖的底层镜像
MAINTAINER:指定镜像创建者
ENV:设置环境变量
RUN:运行shell命令
COPY:将编译机本地文件拷贝到镜像文件系统中
EXPOSE:指定监听端口
ENTRYPOINT:预执行命令,创建容器并启动后才执行
编写Dockerfile
文件的名称必须为Dockerfile
执行命令生成镜像
docker build [OPTIONS] PATH|URL|-
在我的文档里面编写Dockerfile,内容如下!其中“registry.cn-hangzhou.aliyuncs.com/shuodao/tomcat-8.5.27”是通过docker image命令得到的。
FROM registry.cn-hangzhou.aliyuncs.com/shuodao/tomcat-8.5.27
MAINTAINER kgc
COPY /home/docker/Desktop/bg.html /usr/tomcat/webapps/ROOT
EXPOSE 8080/tcp
Dockerfile所在位置
docker@ubuntu:~$ ls
Desktop Downloads Music Public Videos
Documents examples.desktop Pictures Templates
docker@ubuntu:~$ cd Documents/
docker@ubuntu:~/Documents$ ls
Dockerfile
docker@ubuntu:~/Documents$ pwd
/home/docker/Documents
到达该目录下面执行命令,生成镜像。mytomcat要创建的镜像名称, 点(.)代表当前目录
docker@ubuntu:~/Documents$ docker build -t mytomcat .
Sending build context to Docker daemon 2.048 kB
Step 1/4 : FROM registry.cn-hangzhou.aliyuncs.com/shuodao/tomcat-8.5.27
---> d07ca8aba782
Step 2/4 : MAINTAINER kgc
---> Running in 0750db1b7cf9
---> 6f9527ec0041
Removing intermediate container 0750db1b7cf9
Step 3/4 : COPY /home/docker/Desktop/bg.html /usr/tomcat/webapps/ROOT
lstat home/docker/Desktop/bg.html: no such file or directory
根据镜像启动一个tomcat容器
docker@ubuntu:~/Documents$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 6f9527ec0041 19 minutes ago 369 MB
registry.cn-hangzhou.aliyuncs.com/shuodao/tomcat-8.5.27 latest d07ca8aba782 2 months ago 369 MB
docker@ubuntu:~/Documents$ docker run -d -it -p 8080:8080 --name tomcat7 6f9527ec0041
7b6a7478c8cee10a7030cb309607ff01dfe0eb221d1f5c12de2383a8229d5a2e
docker@ubuntu:~/Documents$
在虚拟机(宿主机)上访问浏览器可以http://localhost:8080/,可以看到tomcat
docker的可视化
DockerUI,Shipyard
下载镜像
分别下载以下几个镜像
docker pull rethinkdb
docker pull microbox/etcd
docker pull shipyard/docker-proxy
docker pull swarm
docker pull shipyard/shipyard
手动安装
1.数据存储
Shipyard使用RethinkDB作为数据存储工具,我们需要先运行RethinkDB容器
docker run -ti -d --restart=always --name shipyard-rethinkdb rethinkdb
2.服务发现
docker run -ti -d -p 4001:4001 -p 7001:7001 --restart=always --name shipyard-discovery microbox/etcd:latest -name discovery
3.Docker代理服务
默认情况下,Docker引擎只侦听套接字。 我们可以重新配置引擎以使用TLS,或者您可以使用代理容器。 这是一个非常轻量级的容器,它只是将请求从TCP转发到Docker监听的Unix套接字。
docker run -ti -d -p 2375:2375 --hostname=$HOSTNAME --restart=always --name shipyard-proxy -v /var/run/docker.sock:/var/run/docker.sock -e PORT=2375 shipyard/docker-proxy:latest
4. Swarm管理节点
docker run -ti -d --restart=always --name shipyard-swarm-manager swarm:latest manage --host tcp://0.0.0.0:3375 etcd://<IP-OF-HOST>:4001
5. Swarm Agent节点
docker run -ti -d --restart=always --name shipyard-swarm-agent swarm:latest join --addr <IP-OF-HOST>:2375 etcd://<IP-OF-HOST>:4001
6. Shipyard管理工具
docker run -ti -d --restart=always --name shipyard-controller --link shipyard-rethinkdb:rethinkdb --link shipyard-swarm-manager:swarm -p 8080:8080 shipyard/shipyard:latest server -d tcp://swarm:3375
参数<IP-OF-HOST>指的是docker0的ip地址171.17.0.1
docker@ubuntu:~$ ifconfig
docker0 Link encap:Ethernet HWaddr 02:42:c4:9a:88:f4
inet addr:172.17.0.1 Bcast:0.0.0.0 Mask:255.255.0.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
ens33 Link encap:Ethernet HWaddr 00:0c:29:71:77:bf
inet addr:192.168.117.131 Bcast:192.168.117.255 Mask:255.255.255.0
inet6 addr: fe80::a846:bb2d:e4c:5797/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:126467 errors:0 dropped:0 overruns:0 frame:0
TX packets:35459 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:157635205 (157.6 MB) TX bytes:2284668 (2.2 MB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:714 errors:0 dropped:0 overruns:0 frame:0
TX packets:714 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:74827 (74.8 KB) TX bytes:74827 (74.8 KB)
运行效果:
在虚拟机(宿主机)打开浏览器,输入网址:http://localhost:8080
Shipyard将创建一个默认账号,用户名:admin
,密码:shipyard
。使用该密码登陆:http://<your-host-ip>:8080
如果安装不成功,查看日志
docker logs -f -t --since="2018-06-21" --tail=10 shipyard-controller
或者安装UI for Docker
root@ubuntu:/home/docker# docker pull uifd/ui-for-docker
Using default tag: latest
Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
root@ubuntu:/home/docker# docker pull docker.io/uifd/ui-for-docker
Using default tag: latest
latest: Pulling from uifd/ui-for-docker
841194d080c8: Pull complete
Digest: sha256:fe371ff5a69549269b24073a5ab1244dd4c0b834cbadf244870572150b1cb749
Status: Downloaded newer image for uifd/ui-for-docker:latest
root@ubuntu:/home/docker# docker run -it -d --name docker-web -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock docker.io/uifd/ui-for-docker
a655f3b4a296194c3f587f2e8e275e1686ab39c19ceea805a3bd1da20a272b7b
浏览器输入地址http://192.168.117.131:9000可以访问
如果再次重启服务器,访问地址会报错,需要重启下服务,如果有容器conflict,就先停掉容器,再删除容器
root@ubuntu:/home/docker# docker run -it -d --name docker-web -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock docker.io/uifd/ui-for-docker
docker: Error response from daemon: Conflict. The container name "/docker-web" is already in use by container f8f2b21685cfe850f450fb82dbaeca6a88960b2f5c63420f904a2598b0ba243b. You have to remove (or rename) that container to be able to reuse that name..
See 'docker run --help'.
root@ubuntu:/home/docker# docker stop f8f2b21685cfe850f450fb82dbaeca6a88960b2f5c63420f904a2598b0ba243b
f8f2b21685cfe850f450fb82dbaeca6a88960b2f5c63420f904a2598b0ba243b
root@ubuntu:/home/docker# docker rm f8f2b21685cfe850f450fb82dbaeca6a88960b2f5c63420f904a2598b0ba243b
f8f2b21685cfe850f450fb82dbaeca6a88960b2f5c63420f904a2598b0ba243b
root@ubuntu:/home/docker# docker run -it -d --name docker-web -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock docker.io/uifd/ui-for-docker
9bc037f297a1d11ce1d38bceb93167720f28c62e4c73087ed7fd6852cd3e0d3a
root@ubuntu:/home/docker#
安装SSH服务
解决远程SSH连接root用户拒绝问题
1.更新源列表
打开"终端窗口",输入"sudo apt-get update"-->回车-->"输入当前登录用户的管理员密码"-->回车,就可以了。
2.安装ssh
打开"终端窗口",输入"sudo apt-get install openssh-server"-->回车-->输入"y"-->回车-->安装完成。
3.查看ssh服务是否启动
打开"终端窗口",输入"sudo ps -e |grep ssh"-->回车-->有sshd,说明ssh服务已经启动,如果没有启动,输入"sudo service ssh start"-->回车-->ssh服务就会启动。
4.使用gedit修改配置文件"/etc/ssh/sshd_config"
打开"终端窗口",输入"sudo gedit /etc/ssh/sshd_config"-->回车-->把配置文件中的"PermitRootLogin prohibit-password"加一个"#"号,把它注释掉-->再增加一句"PermitRootLogin yes"-->保存,修改成功。
5.重启ssh服务/etc/init.d/ssh restart;
安装dockerdocker pull centos
创建镜像
1.上传文件
dockerfiles-master.zip
在https://download.csdn.net/download/fulq1234/10427374里面找
src下面的文件夹,没用到是:
jenkins2.73.3
eureka
JIRA7.3.8
konga
kong0.11.2.el7.noarch
mycat1.6
postgresql9.6
./im-1.sh all n
如果部分镜像没成功,可以单独创建镜像(镜像名称和dockerfile文件地址可以在im-1.sh中找到)
./im-1.sh 镜像名称 n dockerfile文件地址
创建容器
./InitContainers-2.sh initim-1.sh的部分内容如下:
# ... ...
images[0]="yi/centos7-ssh"
paths[0]="../src/centos7/"
images[1]="yi/centos7-jdk8u151"
paths[1]="../src/jdk8u151/"
images[2]="yi/centos7-redis"
paths[2]="../src/redis4.0.2/"
images[3]="yi/centos7-ssh-tengine-local"
paths[3]="../src/Nginx-Tengine-2.2.1/local.com/"
images[4]="yi/centos7-ssh-tengine"
paths[4]="../src/Nginx-Tengine-2.2.1/"
images[5]="yi/centos7-mysql5.6.38"
paths[5]="../src/mysql5.6/"
images[6]="yi/centos7-zookeeper3.4.11"
paths[6]="../src/zookeeper3.4.11/"
images[7]="yi/centos7-activemq5.15.2"
paths[7]="../src/activeMQ5.15.2/"
images[8]="yi/centos7-confluence"
paths[8]="../src/Confluence6.3.1/"
images[9]="yi/centos7-jira"
paths[9]="../src/JIRA7.3.8/"
images[10]="yi/centos7-mycat1.6"
paths[10]="../src/mycat1.6/"
images[11]="yi/centos7-tomcat7"
paths[11]="../src/tomcat7/"
images[12]="yi/centos7-dubboadmin284"
paths[12]="../src/dubboadmin284/"
images[13]="yi/centos7-jenkins"
paths[13]="../src/jenkins2.73.3/"
images[17]="yi/centos7-kong"
paths[17]="../src/kong0.11.2.el7.noarch/"
images[15]="yi/centos7-postgresql9.6"
paths[15]="../src/postgresql9.6/"
images[16]="yi/centos7-nodejs"
paths[16]="../src/nodejs/"
images[14]="yi/centos7-eureka"
paths[14]="../src/eureka/"
images[15]="yi/centos7-konga"
paths[15]="../src/konga/"
images[16]="yi/centos7-nexus"
paths[16]="../src/nexus2.11.2-03/"
# ... ...
分布式ID生成器
配置MySQL
目的:修改密码
步骤1.启动容器mysql
可以使用docker UI启动
步骤2.进入mysql控制台
用可视化工具shipyard可以进入mysql控制台。
或者使用命令:docker exec -it containerId/containerName /bin/bash
步骤3.执行命令,实现修改密码。
mysql -uroot -p
use mysql;
update user set password=password("123456") where user='root';
当执行mysql -uroot -p执行错误。
解决MySQL登录ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor)问题
修改配置文件无密码登录,
vi /etc/my.cnf
在最尾部增加
skip-grant-tables
重启mysql
service mysqld restart
设置完密码后,记得把/etc/my.cnf改过来。
步骤4:执行命令,实现mysql 开发远程设置root@ubuntu:/home/docker/tools/dokerfiles-master/env10.1# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e7b107814966 yi/centos7-nexus "/usr/bin/supervisord" 25 minutes ago Up 25 minutes 22/tcp, 8081/tcp env10_207_nexus
5940ef0d91d2 yi/centos7-confluence "/bin/sh -c '/usr/..." 27 minutes ago Up 27 minutes 22/tcp, 8090/tcp env10_201_confluence
87454b9073e9 yi/centos7-activemq5.15.2 "/usr/bin/supervisord" 27 minutes ago Up 27 minutes 22/tcp, 8161-8162/tcp env10_6_Mq01
a9a7d7852588 yi/centos7-mysql5.6.38 "/usr/bin/supervisord" 28 minutes ago Up 28 minutes 22/tcp, 0.0.0.0:3306->3306/tcp env10_4_Mysql01
56f42e6a7ca4 yi/centos7-redis "/usr/bin/supervisord" 28 minutes ago Up 28 minutes 22/tcp, 0.0.0.0:6379->6379/tcp env10_3_Redis01
5ccc0fc44eab yi/centos7-ssh-tengine-local "/usr/bin/supervisord" 28 minutes ago Up 28 minutes 22/tcp, 0.0.0.0:80->80/tcp env10_2_Nginx01
ce123ec2609e docker.io/uifd/ui-for-docker "/ui-for-docker" 14 hours ago Up 14 hours 0.0.0.0:9000->9000/tcp docker-web
root@ubuntu:/home/docker/tools/dokerfiles-master/env10.1# docker exec -it a9a7d7852588 /bin/bash
[root@a9a7d7852588 mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.38 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set password=password("123456") where user='root';
Query OK, 4 rows affected (0.40 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.06 sec)
mysql> grant all privileges on *.* to root@'%' identified by '123456' with grant option;
Query OK, 0 rows affected (0.16 sec)
mysql>
注意如果连不上,需要修改etc/redis.conf。这里已经修改好了。
activeMQ的访问地址是mq.local.com
修改win7的C:\Windows\System32\drivers\etc\hosts
192.168.117.131 da.local.com
192.168.117.131 mq.local.com
如果启动成功后,没问题的话。浏览器输入以下地址可以访问
da.local.com
mq.local.com
question1.浏览器地址访问da.local.com,需要输入用户名和密码,查看dubbo登录用户名密码:
dokerfiles-master\src\dubboadmin284\dubbo.propertiesroot@ubuntu:/home/docker/tools/dokerfiles-master/env10.1# docker ps|grep mq
87454b9073e9 yi/centos7-activemq5.15.2 "/usr/bin/supervisord" About an hour ago Up About an hour 22/tcp, 8161-8162/tcp env10_6_Mq01
root@ubuntu:/home/docker/tools/dokerfiles-master/env10.1# docker exec -it 87454b9073e9 /bin/bash
[root@87454b9073e9 local]# ps -ef|grep mq
root 84 69 0 03:41 ? 00:00:00 grep --color=auto mq
[root@87454b9073e9 local]# cd /
[root@87454b9073e9 /]# cd usr/local/
[root@87454b9073e9 local]# ls
apache-activemq-5.15.2 etc include lib libexec share supervisord.log
bin games java lib64 sbin src supervisord.pid
[root@87454b9073e9 local]# cd apache-activemq-5.15.2/
[root@87454b9073e9 apache-activemq-5.15.2]# cd bin
[root@87454b9073e9 bin]# ls
activemq activemq.jar linux-x86-32 macosx
activemq-diag env linux-x86-64 wrapper.jar
[root@87454b9073e9 bin]# ./activemq start
INFO: Loading '/usr/local/apache-activemq-5.15.2//bin/env'
INFO: Using java '/usr/local/java/jdk1.8.0_161/bin/java'
INFO: Starting - inspect logfiles specified in logging.properties and log4j.prop erties to get details
INFO: pidfile created : '/usr/local/apache-activemq-5.15.2//data/activemq.pid' ( pid '116')
[root@87454b9073e9 bin]# ps -ef|grep mq
root 116 0 30 03:43 ? 00:00:02 /usr/local/java/jdk1.8.0_161/b in/java -Xms64M -Xmx1G -Djava.util.logging.config.file=logging.properties -Djava .security.auth.login.config=/usr/local/apache-activemq-5.15.2//conf/login.config -Dcom.sun.management.jmxremote -Djava.awt.headless=true -Djava.io.tmpdir=/usr/l ocal/apache-activemq-5.15.2//tmp -Dactivemq.classpath=/usr/local/apache-activem -5.15.2//conf:/usr/local/apache-activemq-5.15.2//../lib/: -Dactivemq.home=/usr/l ocal/apache-activemq-5.15.2/ -Dactivemq.base=/usr/local/apache-activemq-5.15.2/ -Dactivemq.conf=/usr/local/apache-activemq-5.15.2//conf -Dactivemq.data=/usr/loc al/apache-activemq-5.15.2//data -jar /usr/local/apache-activemq-5.15.2//bin/acti vemq.jar start
root 121 69 2 03:43 ? 00:00:00 grep --color=auto mq
docker exec -it 87454b9073e9 /bin/bash | /bin/bash 进入mq容器 |
ps -ef|grep mq | 检查mq是否启动 |
./activemq start | 启动mq |
question4.如果da.local.com访问不到,找错
首先看镜像(docker images)和容器(docker ps),有dubbo,但是没有zookeeper,dubbo需要zookeeper作为注册中心.
现在安装:
./im-1.sh yi/centos7-zookeeper3.4.11 n ../src/zookeeper3.4.11/
报错,一个包下载失败
#RUN wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz
RUN wget http://archive.apache.org/dist/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz
总结:配置docker遇到的坑
大数据开发工程师3.0标准版-项目集群\18.基于Dubbox微服实战-双11抢购项目\4.运行及部署资料\dokerfiles-master
执行命令 ./im-1.sh all n之前,先要做
1.src下面的文件夹,没用到是:
jenkins2.73.3
eureka
JIRA7.3.8
konga
kong0.11.2.el7.noarch
mycat1.6
postgresql9.6
3.修改文件:大数据开发工程师3.0标准版-项目集群\18.基于Dubbox微服实战-双11抢购项目\4.运行及部署资料\dokerfiles-master2\dokerfiles-master\src\tomcat7\Dockerfile
说明:#注释掉的部分,是原来的内容,这个资源不能get到。
#RUN wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.85/bin/apache-tomcat-7.0.85.tar.gz
RUN wget https://archive.apache.org/dist/tomcat/tomcat-7/v7.0.85/bin/apache-tomcat-7.0.85.tar.gz
4.修改文件:大数据开发工程师3.0标准版-项目集群\18.基于Dubbox微服实战-双11抢购项目\4.运行及部署资料\dokerfiles-master\src\zookeeper3.4.11\Dockerfile
说明:#注释掉的部分,是原来的内容,这个资源不能get到。
#RUN wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz
RUN wget http://archive.apache.org/dist/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz
5.修改文件:大数据开发工程师3.0标准版-项目集群\18.基于Dubbox微服实战-双11抢购项目\4.运行及部署资料\dokerfiles-master\dokerfiles-master\src\jdk8u151\Dockerfile
#RUN wget --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie;" http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jdk-8u161-linux-x64.tar.gz
RUN wget --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie;" http://download.oracle.com/otn/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jdk-8u161-linux-x64.tar.gz?AuthParam=1527648187_ea8176d0a8ab3f1e23d61d0a8aba17d0
RUN tar -zxvf jdk-8u161-linux-x64.tar.gz?AuthParam=1527648187_ea8176d0a8ab3f1e23d61d0a8aba17d0
RUN rm jdk-8u161-linux-x64.tar.gz?AuthParam=1527648187_ea8176d0a8ab3f1e23d61d0a8aba17d0
RUN mv -f jdk1.8.0_161/ /usr/local/java/jdk1.8.0_161
注意要选择下载文件的地址,后面的AuthParam是随时变化的。注意。下载好的文件叫“jdk-8u161-linux-x64.tar.gz?AuthParam=1527648187_ea8176d0a8ab3f1e23d61d0a8aba17d0”,解压后文件叫jdk1.8.0_161。根据linux运行结果适时修改。
如果想用一台机器连接另一台机器的虚拟机。http://www.jb51.net/article/133884.htm
如果是单独安装一个ubuntu系统,连不上网。解决方法:https://blog.csdn.net/u013305783/article/details/72865187?utm_source=itdadao&utm_medium=referral
错误1:
命令:apt-get install -y docker.io
错误:unable to locate package docker.io
解决命令:apt install yum
错误:unable to locate package yum
解决命令:sudo apt-get update
错误:unable to lock directory /var/lib/apt/lists
解决命令:sudo rm /var/lib/apt/lists/lock
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。