我正在使用Docker,我正在尝试使用docker-java API从dockerfile构建映像。 Here你可以找到如何做到这一点,我做了同样的事情:
protected void createDocker(DockerBuildRequestContext requestContext) throws Exception {
InputStream response = dockerClient.buildImageCmd(requestContext.getBuildDir()).exec();
StringWriter logwriter = new StringWriter();
try {
LineIterator itr = IOUtils.lineIterator(response, "UTF-8");
while (itr.hasNext()) {
String line = itr.next();
logwriter.write(line);
LOG.info(line);
}
} finally {
IOUtils.closeQuietly(response);
}
但我得到了这个例外:
com.github.dockerjava.api.model.Info@47a4d139[containers=2,debug=false,driver=aufs,driverStatuses=[[Root Dir, /var/lib/docker/aufs], [Dirs, 40]],executionDriver=native-0.2,IPv4Forwarding=1,images=36,IndexServerAddress=https://index.docker.io/v1/,initPath=/usr/bin/docker,initSha1=,kernelVersion=3.13.0-39-generic,memoryLimit=true,nEventListener=0,NFd=11,NGoroutines=11,sockets=<null>,swapLimit=0]
Build docker located at: /home/mati/Projects/engage/server/platforms/preserve/engage-app/engage-app-docker/target/docker/tomcat7-base and tagged: tomcat-base
com.github.dockerjava.api.DockerClientException: Error occurred while preparing Docker context folder.
at com.github.dockerjava.core.command.BuildImageCmdImpl.buildDockerFolderTar(BuildImageCmdImpl.java:222)
at com.github.dockerjava.core.command.BuildImageCmdImpl.<init>(BuildImageCmdImpl.java:48)
at com.github.dockerjava.core.DockerClientImpl.buildImageCmd(DockerClientImpl.java:228)
at com.starmount.engage.app.DockerBuilder.createDocker(DockerBuilder.java:191)
at com.starmount.engage.app.DockerBuilder.handleDockerCreationRequest(DockerBuilder.java:72)
at com.starmount.engage.app.DockerBuilder.main(DockerBuilder.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.io.IOException: This archives contains unclosed entries.
at org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.finish(TarArchiveOutputStream.java:216)
at org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.close(TarArchiveOutputStream.java:231)
at com.github.dockerjava.core.CompressArchiveUtil.archiveTARFiles(CompressArchiveUtil.java:34)
at com.github.dockerjava.core.command.BuildImageCmdImpl.buildDockerFolderTar(BuildImageCmdImpl.java:217)
... 10 more
我认为问题是Dockerfile,但是如果我尝试从终端创建Image
docker build -t myDockerImageName ./docker/location/
创建图像没有问题。
这是我的Dockerfile:
FROM ubuntu:precise
MAINTAINER kummo <kummo666@gmail.com>
ENV LANGUAGE en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8
RUN locale-gen en_US.UTF-8 && DEBIAN_FRONTEND=noninteractive dpkg-reconfigure locales
RUN apt-get update && apt-get -y --force-yes install wget
ADD sources.list /etc/apt/sources.list.d/postgres.list
RUN wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add -
RUN mkdir /var/lib/postgresql
RUN adduser --system --disabled-login --home /var/lib/postgresql --no-create-home \
--group --gecos "PostgreSQL administrator" --shell /bin/bash \
--uid 5432 postgres
RUN apt-get update --no-list-cleanup\
&& DEBIAN_FRONTEND=noninteractive apt-get -y --force-yes install postgresql-9.3 \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
ADD pg_hba.conf /etc/postgresql/9.3/main/pg_hba.conf
ADD postgresql.conf /etc/postgresql/9.3/main/postgresql.conf
USER postgres
# Expose the PostgreSQL port
EXPOSE 5432
# Set the default command to run when starting the container
CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"]
任何人都可以帮助我吗?
谢谢!