基于tutum/lamp镜像搭建GoLang网络应用

delphiwcdj · · 3303 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

2015-01-27 wcdj

摘要:Docker Hub上有较多的LAMP镜像,其中tutum/lamp镜像较为出名,本文使用tutum/lamp作为基础镜像,并在其上添加go编译环境,然后创建和测试一个支持GoLang网络应用的镜像。


过程如下:

1,从Docker Hub下载tutum/lamp镜像

root@gerryyang:~# docker search -s 5 lamp
NAME                      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
tutum/lamp                LAMP image - Apache listens in port 80, an...   47                   [OK]
dockerfiles/centos-lamp                                                   8                    [OK]
root@gerryyang:~# docker pull tutum/lamp
Pulling repository tutum/lamp
b84edafb1623: Download complete 
511136ea3c5a: Download complete 
d497ad3926c8: Download complete 
ccb62158e970: Download complete 
e791be0477f2: Download complete 
3680052c0f5c: Download complete 
22093c35d77b: Download complete 
5506de2b643b: Download complete 
47736d0699b6: Download complete 
59fd8a267ae4: Download complete 
841e457fbafa: Download complete 
a4764b4cd917: Download complete 
0541e94da879: Download complete 
4a3d27d06fa4: Download complete 
7a8e713e5398: Download complete 
723faab6a94a: Download complete 
b951305b9a69: Download complete 
09d2bbb9c055: Download complete 
ccef939b216c: Download complete 
4458c9f101a6: Download complete 
889d08af8392: Download complete 
df75de2ea944: Download complete 
ccb86d616ddf: Download complete 
cb81542002b8: Download complete 
36ca8ec2e1b6: Download complete 
4534351c7b4a: Download complete 
05bcfc7588b0: Download complete 
14e5b41d2a83: Download complete 
41d45c51a5df: Download complete 
Status: Downloaded newer image for tutum/lamp:latest
root@gerryyang:~# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
tutum/lamp                      latest              b84edafb1623        3 months ago        436.7 MB


2,启动tutum/lamp容器,并测试服务访问是否ok

root@gerryyang:~# docker run -d -p 40080:80 -p 43306:3306 tutum/lamp
54a001909fd1746a07876c6cba70b681b9826580ce90d7f7f5a22d22226bf6e5
root@gerryyang:~# docker ps a
CONTAINER ID        IMAGE                                COMMAND             CREATED             STATUS              PORTS                                                                  NAMES
54a001909fd1        tutum/lamp:latest                    "/run.sh"           5 seconds ago       Up 4 seconds        0.0.0.0:40080->80/tcp, 0.0.0.0:43306->3306/tcp                         romantic_yonath       
3fa70f39af75        ubuntu_sshd_gcc_nginx_gerry:14.04    "/run.sh"           About an hour ago   Up About an hour    0.0.0.0:30022->22/tcp, 0.0.0.0:30080->80/tcp, 0.0.0.0:30443->443/tcp   distracted_wilson     
101bc295b601        ubuntu_sshd_gcc_apache_gerry:14.04   "/run.sh"           2 hours ago         Up 2 hours          0.0.0.0:20022->22/tcp, 0.0.0.0:20080->80/tcp                           suspicious_sinoussi   
cec21c3c0a1f        registry:latest                      "docker-registry"   2 hours ago         Up 2 hours          0.0.0.0:5000->5000/tcp                                                 boring_torvalds       
6906a758711c        ubuntu_sshd_gcc_gerry:14.04          "/run.sh"           2 hours ago         Up 2 hours          0.0.0.0:10022->22/tcp                                                  determined_kirch      


3,基于镜像 tutum/lamp:latest 使用 Dockerfile 编译一个GoLang网络服务的镜像 tutum_lamp_golang_gerry:1.0

Dockerfile源码请见GitHub

root@gerryyang:~/golang_tutum_lamp# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
tutum_lamp_golang_gerry         1.0                 6b660dc40f2b        2 minutes ago       661.4 MB
tutum/lamp                      latest              b84edafb1623        3 months ago        436.7 MB
带有GoLang app的镜像已经创建好了,使用debug.sh脚本进入容器确认服务是否正常,比如,启动脚本路径是否正确,二进制文件是否已经生成。



4,以后台的方式启动容器,即启动GoLang服务,并通过外网测试

docker run -d -p 9090:9090  tutum_lamp_golang_gerry:1.0

root@gerryyang:~# docker ps a
CONTAINER ID        IMAGE                                COMMAND             CREATED             STATUS              PORTS                                                                    NAMES
49ce9a13a90a        ubuntu_sshd_gcc_golang_gerry:14.04   "/run.sh"           8 minutes ago       Up 8 minutes        0.0.0.0:9001->9001/tcp, 0.0.0.0:50022->22/tcp                            dreamy_bohr          
dd74c290bfb2        tutum_lamp_golang_gerry:1.0          "/run.sh"           8 minutes ago       Up 8 minutes        0.0.0.0:9090->9090/tcp, 0.0.0.0:50080->80/tcp, 0.0.0.0:53306->3306/tcp   gloomy_galileo       
f24cdc4601f0        tutum/lamp:latest                    "/run.sh"           8 minutes ago       Up 8 minutes        0.0.0.0:40080->80/tcp, 0.0.0.0:43306->3306/tcp                           berserk_nobel        
0558ae51d1bb        ubuntu_sshd_gcc_nginx_gerry:14.04    "/run.sh"           8 minutes ago       Up 8 minutes        0.0.0.0:30022->22/tcp, 0.0.0.0:30080->80/tcp, 0.0.0.0:30443->443/tcp     high_wozniak         
22181d74ab6d        ubuntu_sshd_gcc_apache_gerry:14.04   "/run.sh"           8 minutes ago       Up 8 minutes        0.0.0.0:20022->22/tcp, 0.0.0.0:20080->80/tcp                             backstabbing_bell1   
1bcd2f542592        registry:latest                      "docker-registry"   8 minutes ago       Up 8 minutes        0.0.0.0:5000->5000/tcp                                                   desperate_sammet     
9454db5b40f2        ubuntu_sshd_gcc_gerry:14.04          "/run.sh"           8 minutes ago       Up 8 minutes        0.0.0.0:10022->22/tcp                                                    admiring_hypatia     
通过外网测试服务是否可以访问



注意:使用Dockerfile创建镜像时,会继承父镜像的开放端口,但却不会继承启动命令,因此要再子镜像的run.sh启动脚本里指定要启动的服务,否则父镜像已有的服务无法访问。





有疑问加站长微信联系(非本文作者)

本文来自:CSDN博客

感谢作者:delphiwcdj

查看原文:基于tutum/lamp镜像搭建GoLang网络应用

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

3303 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传