英文:
Dockerfile connect to ODBC(e.g. HPE Vertica) setup
问题
我有一个简单的GO程序,可以成功连接到我的Ubuntu服务器上的Vertica数据库。我已经在这个Ubuntu上设置了**.dobc.ini和odbc驱动程序**。
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("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()
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 <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"]
and I am getting
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"
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 <prataksha.gurung@mydomain.net>
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 && rm vertica-client-8.1.1-0.x86_64.tar.gz
RUN apt-get install -y unixodbc-dev
ADD .odbc.ini /root/.odbc.ini #-->your custom DNS setup
ADD vertica.ini /root/vertica.ini #-->extra odbc driver setup
ADD main /usr/bin/main #-->binary executable
ENTRYPOINT ["main"]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论