Dockerfile连接到ODBC(例如HPE Vertica)设置

huangapple go评论92阅读模式
英文:

Dockerfile connect to ODBC(e.g. HPE Vertica) setup

问题

我有一个简单的GO程序,可以成功连接到我的Ubuntu服务器上的Vertica数据库。我已经在这个Ubuntu上设置了**.dobc.iniodbc驱动程序**。

db, err := sql.Open("odbc", "DSN=HPVerticaDSN")
if err != nil {
    log.Fatal(err)
}

log.Println("DB ping started...")
if err = db.Ping(); err != nil {
    log.Fatalf("DB ping failed with error...%v", err)
}
log.Println("DB connected.")
defer db.Close()

现在,我该如何设置Dockerfile以在Docker容器中运行它?是否可以使用轻量级的基础镜像,比如alpine,还是必须使用ubuntu基础镜像?如果有示例,将不胜感激。

这是我的Dockerfile

FROM alpine:latest
MAINTAINER Prataksha Gurung <prataksha.gurung@mydomain.net>
RUN apk add --no-cache ca-certificates
ADD libverticaodbc.so /libverticaodbc.so
ADD .odbc.ini ~/.odbc.ini
ADD main /usr/bin/main
ENTRYPOINT ["main"]

当我运行这个容器时,我得到以下错误:

panic: standard_init_linux.go:178: exec user process caused "no such file or directory" [recovered]
panic: standard_init_linux.go:178: exec user process caused "no such file or directory"
英文:

I have a simple GO program which successfully connects to Vertica in my ubuntu server. I have setup the .dobc.ini and odbc drvier in this ubuntu.

db, err := sql.Open(&quot;odbc&quot;, &quot;DSN=HPVerticaDSN&quot;)
if err != nil {
	log.Fatal(err)
}

log.Println(&quot;DB ping started...&quot;)
if err = db.Ping(); err != nil {
	log.Fatalf(&quot;DB ping failed with error...%v&quot;, err)
}
log.Println(&quot;DB connected.&quot;)
defer db.Close()

Now, How do I setup the Dockerfile to run this in docker container. Is it possible to use light weight base image like alpine or we have to use ubuntu base image. Any examples would be greatly appreciated.

Here is my Dockerfile

FROM alpine:latest
MAINTAINER Prataksha Gurung &lt;prataksha.gurung@mydomain.net&gt;
RUN apk add --no-cache ca-certificates
ADD libverticaodbc.so /libverticaodbc.so
ADD .odbc.ini ~/.odbc.ini
ADD main /usr/bin/main
ENTRYPOINT [&quot;main&quot;]

and I am getting

panic: standard_init_linux.go:178: exec user process caused &quot;no such file or directory&quot; [recovered]
panic: standard_init_linux.go:178: exec user process caused &quot;no such file or directory&quot;

when I run this container.

答案1

得分: 1

最终我成功地使用以下的dockerfile工作:

FROM ubuntu:artful
MAINTAINER Prataksha Gurung <prataksha.gurung@mydomain.net>
RUN apt-get update
RUN apt-get install -y curl
# 下载适用于此docker环境的相关Linux驱动程序
RUN curl -O https://my.vertica.com/client_drivers/8.1.x/8.1.1-0/vertica-client-8.1.1-0.x86_64.tar.gz
RUN ls -la
RUN tar vzxf vertica-client-8.1.1-0.x86_64.tar.gz && rm vertica-client-8.1.1-0.x86_64.tar.gz
RUN apt-get install -y unixodbc-dev
ADD .odbc.ini /root/.odbc.ini         # --> 您的自定义DNS设置
ADD vertica.ini /root/vertica.ini     # --> 额外的ODBC驱动程序设置
ADD main /usr/bin/main                # --> 二进制可执行文件
ENTRYPOINT ["main"]
英文:

Finally I managed it to work with this dockerfile:

FROM ubuntu:artful
MAINTAINER Prataksha Gurung &lt;prataksha.gurung@mydomain.net&gt;
RUN apt-get update
RUN apt-get install -y curl
#downloading the relevant linux driver for this docker environment
RUN curl -O https://my.vertica.com/client_drivers/8.1.x/8.1.1-0/vertica-client-8.1.1-0.x86_64.tar.gz
RUN ls -la
RUN tar vzxf vertica-client-8.1.1-0.x86_64.tar.gz &amp;&amp; rm vertica-client-8.1.1-0.x86_64.tar.gz
RUN apt-get install -y unixodbc-dev
ADD .odbc.ini /root/.odbc.ini         #--&gt;your custom DNS setup
ADD vertica.ini /root/vertica.ini     #--&gt;extra odbc driver setup
ADD main /usr/bin/main                #--&gt;binary executable
ENTRYPOINT [&quot;main&quot;]

huangapple
  • 本文由 发表于 2017年7月19日 19:54:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/45189777.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定