无法使用docker查看STDERR输出

我正在运行一个php docker镜像(php:5.6-apache),它有apache错误,访问日志重定向到 STDERR和STDOUT分别使用符号链接。</ p>

当我在前台运行docker镜像或访问docker容器日志时,我可以看到STDOUT输出。 但我没有看到任何错误(即使我生成php错误)。</ p>

知道为什么会这样,以及如何解决它?</ p>

我正在为Mac运行docker(但我认为这没有任何区别)</ p>

谢谢</ p>

  access.log  -  &GT;  /dev/stdout
error.log - &gt; /dev/stderr
other_vhosts_access.log - &gt; / dev / stdout
</ code> </ pre>

编辑/解决:</ strong>
如下@BMitch提及并证明,STDERR重定向工作正常。

问题出在PHP配置上。 如果我使用 error_log()</ code>记录错误,它将输出到日志。 但是如果我有一个php错误,比如调用一个未定义的函数,错误将永远不会出现在日志中。 这似乎有点不一致。 在任何情况下,...... </ p>

我必须在 / usr / local / etc / php / </ code中创建 php.ini </ code>文件 >并添加以下两个参数:</ p>

  log_errors = On 
error_log = /var/log/apache2/error.log
</ pre>
\ n

然后重新启动docker容器。 这导致所有PHP错误被记录并输出到STDERR。 有关示例,请参阅@ German的答案。</ p>
</ div>

展开原文

原文

I'm running a php docker image (php:5.6-apache) which has apache's error and access logs redirected to STDERR and STDOUT respectively using symbolic links.

When I run the docker image in the foreground or access the docker container logs, I can see the STDOUT output. But I don't see any errors (even when I generate php errors).

Any idea why that is and how I can fix it?

I'm running docker for Mac (but I don't think this makes any difference)

Thanks

access.log -> /dev/stdout
error.log -> /dev/stderr
other_vhosts_access.log -> /dev/stdout

Edit / Solved: As @BMitch mentions and proves below, the STDERR redirection works fine. The problem was with PHP configuration. If I logged an error with error_log(), it would get output to the log. But if I had a php error, like calling an undefined function, the error would never appear in the log. This seems a little inconsistent. In any case, ...

I had to create a php.ini file in /usr/local/etc/php/ and add these two parameters:

log_errors = On
error_log = /var/log/apache2/error.log

and then restart the docker container. This caused all PHP errors to be logged and output to STDERR. See @German's answer for an example.

dtvjl64442
dtvjl64442 是的,但只有/var/www
大约 3 年之前 回复
duanmanpi9358
duanmanpi9358 你装了任何卷吗?
大约 3 年之前 回复

3个回答



我无法重现您的情况。 如果以下内容无效,请提供错误的 mcve 。</ p>

基本 Dockerfile:</ p>

  $ cat Dockerfile 
FROM php:5.6-apache
COPY。 / var / www / html /
</ code> </ pre>

唯一的php是生成错误的文件:</ p>

  $  cat error.php 
&lt;?
error_log(“Hello错误日志。”)
?&gt;
</ code> </ pre>

构建并运行它:</ p> \ n

  $ docker build -t test-php。
将构建上下文发送到Docker守护程序3.072kB
Step 1/2:FROM php:5.6-apache
---&gt; f16436448ebd
Step 2/2:复制。 / var / www / html /
n ---&gt; 使用缓存
---&gt; cfe66485e2cc
成功构建了cfe66485e2cc
成功标记了test-php:最新

$ docker run -p 8080:80 -d --name test-php test-php
7f9a1836a8157963966b583579dff94c6413292547b84d22957add77ad2d8e14
</ code> </ pre>

Curl按预期为空,但调用它会在日志中生成错误:</ p>

  $ curl localhost:8080 / error.php 
</ code> </ pre>

显示stdout日志,将错误重定向到/ dev / null:</ p>

  $ docker logs test-php 2&gt; / dev / null \  n172.17.0.1  -   -  [31 / May / 2017:00:06:37 +0000]“GET /error.php HTTP / 1.1”200 174“ - ”“curl / 7.38.0”
</ code> </ pre>

显示stderr日志,将stdout重定向到/ dev / null </ p>

  $ docker logs test-php&gt; / dev / null 
AH00558 :apache2:无法使用172.17.0.2可靠地确定服务器的完全限定域名。 全局设置'ServerName'指令以禁止显示此消息
AH00558:apache2:无法使用172.17.0.2可靠地确定服务器的完全限定域名。 全局设置'ServerName'指令以禁止此消息
[n May 31 00:06:25.064546 2017 Wed] [mpm_prefork:notice] [pid 1] AH00163:Apache / 2.4.10(Debian)PHP / 5.6.30已配置 - - 恢复正常运营
[星期三3月31日00:06:25.064584 2017年] [核心:通知] [pid 1] AH00094:命令行:'apache2 -D FOREGROUND'
[Wed May 31 00:06:37.833470 2017] [:error] [pid 17] [client 172.17.0.1:50040] Hello错误日志。
</ code> </ pre>

注意错误输出的最后一行。</ p>

</ div>

展开原文

原文

I'm unable to reproduce your situation. If the below doesn't help, please provide an mcve of your error.

Basic Dockerfile:

$ cat Dockerfile 
FROM php:5.6-apache
COPY . /var/www/html/

The only php is this file to generate an error:

$ cat error.php 
<?
error_log("Hello error log.")
?>

Build and run it:

$ docker build -t test-php .
Sending build context to Docker daemon  3.072kB
Step 1/2 : FROM php:5.6-apache
 ---> f16436448ebd
Step 2/2 : COPY . /var/www/html/
 ---> Using cache
 ---> cfe66485e2cc
Successfully built cfe66485e2cc
Successfully tagged test-php:latest

$ docker run -p 8080:80 -d --name test-php test-php
7f9a1836a8157963966b583579dff94c6413292547b84d22957add77ad2d8e14

Curl is empty as expected, but calling it generates an error in the logs:

$ curl localhost:8080/error.php

Show stdout logs, redirecting error to /dev/null:

$ docker logs test-php 2>/dev/null
172.17.0.1 - - [31/May/2017:00:06:37 +0000] "GET /error.php HTTP/1.1" 200 174 "-" "curl/7.38.0"

Show stderr logs, redirecting stdout to /dev/null

$ docker logs test-php >/dev/null
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
[Wed May 31 00:06:25.064546 2017] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/5.6.30 configured -- resuming normal operations
[Wed May 31 00:06:25.064584 2017] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
[Wed May 31 00:06:37.833470 2017] [:error] [pid 17] [client 172.17.0.1:50040] Hello error log.

Note the last line of the error output.

douwen5066
douwen5066 这对我来说没有按预期工作,结果一切都记录为stderr。 检查原始日志数据(假设默认json文件日志驱动程序)少<$(docker inspect -f'{{。LogPath}}'CONTAINER)
11 个月之前 回复
duangang4940
duangang4940 今天早上我和这个人打架但是没时间了。 我相信php.ini需要更新,但我无法应用我的更改(可能为5.6版本编写了错误的文件)。 这个问题在php方面有更详细的介绍:stackoverflow.com/questions/1053424 / ...
大约 3 年之前 回复
duanmi4379
duanmi4379 是的,如果你直接调用error_log(),它似乎工作。 但是如果你调用error_pug()(当然不存在),日志不会显示任何错误。 您只在浏览器中收到错误消息。
大约 3 年之前 回复



在我的情况下,我错过了这个神奇的设置(默认情况下为“no”):</ p>

  #/ etc / php / 7.0 / fpm / pool.d / www.conf 
catch_workers_output = yes
</ code> </ pre>

在此处找到 Symfony记录到Docker容器内的stdout </ p>
</ div>

展开原文

原文

In my case I was missing this magic setting ("no" by default):

#/etc/php/7.0/fpm/pool.d/www.conf
catch_workers_output = yes

Found it here Symfony logs to stdout inside Docker container



如果你想在apache2日志中看到php错误,你必须激活它们。 为此,您必须将 php.ini </ code>文件写入文件夹 / usr / local / etc / php </ code>。</ p>

I 在存储库中编写了一个示例,以便可以看到该示例。</ p>

https://github.com/nitzap/stackoverflow-docker-php-error-log </ p>

如果你想看到stdout和stderr 日志,您可以使用以下命令在容器外部执行此操作:</ p>

  docker logs&lt; name_container&gt; 
</ code> </ pre>

现在,如果你想在日志中保持附加,可以在tail命令中添加-f选项。</ p>

  docker logs&lt; name_container&gt;  -f 
</ code> </ pre>
</ div>

展开原文

原文

If you want to see the php errors in the apache2 log you have to activate them. For this you have to write to the php.ini file into the folder /usr/local/etc/php.

I wrote an example in a repository so that the example can be seen.

https://github.com/nitzap/stackoverflow-docker-php-error-log

If you want to see the stdout and stderr logs, you can do it with the following command, outside of your containers:

docker logs <name_container>

Now if you want to remain attached in the log you can add the -f option as in the tail command.

docker logs <name_container> -f

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Python+OpenCV计算机视觉

Python+OpenCV计算机视觉

Docker Golang SDK-如何将容器标准输出重定向到文件

<div class="post-text" itemprop="text"> <p>Using the docker golang sdk the following method can be used to create a container and bind it's output to <code>stdout</code>.</p> <pre><code>resp, err := cli.ContainerCreate(ctx, &amp;container.Config{ Image: "alpine", Cmd: []string{"echo", "Hello World"}, AttachStdout: true, }, nil, nil, "") </code></pre> <p>How can I redirect this output to a file using the SDK ? I'm using the official SDK of docker - <code>github.com/docker/docker/client</code></p> </div>

如何从正在运行的Docker容器中读取文件和标准输出

<div class="post-text" itemprop="text"> <p>我该如何在主机中启动应用程序以便从正在运行的Docker容器中读取文件和标准输出? 其实我想这样做:</p> <pre><code>docker start containerid ./myapp // This app will *somehow* have access files and stdout generated by the container I just stared. </code></pre> <p>我该怎么做呢?更具体地说,我想说的是;我想从docker容器中读取日志和标准输出,并在其他地方处理这些日志。 我也愿意创建另一个docker容器,它可以从另一个容器读取文件和标准输出,但我不知道这是否是可能的。</p> </div>

如何将标准输出从Docker容器重定向到主机

<div class="post-text" itemprop="text"> <p>I'm trying to call docker's mysqldump from host system for save mysql dump from golang. It works correctly with host mysqldump, but don't work with docker's mysqldump. </p> <pre><code>func writeDb(dbName string) { var mysqldumpPath string = "/usr/bin/mysqldump" //var mysqldumpPath string = "/Applications/MAMP/Library/bin/mysqldump" //cmd := exec.Command(mysqldumpPath, fmt.Sprintf("-u%s", USER), fmt.Sprintf("-p%s", PASSWORD) , dbName) cmd := exec.Command("docker", "exec", "some-mysql", mysqldumpPath, fmt.Sprintf("%s", USER), fmt.Sprintf("-p%s", PASSWORD) , dbName, "&gt;", fmt.Sprintf("%s.sql", dbName)) stdout, err := cmd.StdoutPipe() if err != nil { log.Fatal(err) } if err := cmd.Start(); err != nil { log.Fatal(err) } bytes, err := ioutil.ReadAll(stdout) if err != nil { log.Fatal(err) } err = ioutil.WriteFile("./backup/" + dbName +".sql", bytes, 0644) if err != nil { panic(err) } </code></pre> <p>}</p> <p>I got only that for non-empty database <a href="https://i.stack.imgur.com/Xj9k0.png" rel="nofollow noreferrer">empty mysql dump</a></p> </div>

从Docker SDK中的容器中获取输出

<div class="post-text" itemprop="text"> <p>I'm trying to run a container using Docker SDK for golang and I can't get the output from the container. I'm using the following code for that that actually runs the container, but doesn't sends back stderr and stdout of the application. Can you advice what I'm doing wrong?</p> <pre><code>type dckr struct { cli *client.Client username string password string addr string ctx context.Context } func (d *dckr) Run(containername string, image string, command []string, bind []string, stdout io.Writer, stderr io.Writer) error { log.Printf("[Create] %s -&gt; %s ", image, containername) res, err := d.cli.ContainerCreate( d.ctx, &amp;container.Config{ User: "root", AttachStdout: true, AttachStderr: true, Image: image, Cmd: command, }, &amp;container.HostConfig{ AutoRemove: true, Binds: bind, }, &amp;network.NetworkingConfig{}, containername, ) if err != nil { log.Println("[Create] Failed. %s", err) return err } defer d.cli.ContainerRemove(d.ctx, res.ID, types.ContainerRemoveOptions{Force: true}) log.Printf("[Create] id: %s ", res.ID) for wrn := range res.Warnings { log.Printf("[Create] %s ", wrn) } rsp, err := d.cli.ContainerAttach(d.ctx, containername, types.ContainerAttachOptions{ Stream: false, Stdout: true, Stderr: true, Logs: true, }) if err != nil { log.Printf("[Attach] Fail. %s ", err) return err } log.Printf("[Attach] %s", res.ID) defer rsp.Close() err = d.cli.ContainerStart(d.ctx, res.ID, types.ContainerStartOptions{}) if err != nil { log.Printf("[Run] Fail. %s ", err) return err } _, err = stdcopy.StdCopy(stdout, stderr, rsp.Reader) return err } </code></pre> </div>

无法使用golang docker sdk从docker容器获取日志

<div class="post-text" itemprop="text"> <p>I want to compile untrusted code in docker container, so I want to test exec command</p> <pre><code>import ( "context" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" log "github.com/sirupsen/logrus" "io" "os" ) func main() { dockerClient, err := client.NewClientWithOpts(client.WithVersion("1.38")) if err != nil{ log.Error("error when create dockerClient ",err) } ctx := context.Background() container, err := dockerClient.ContainerCreate(ctx,&amp;container.Config{ Image:"golang", OpenStdin:true, Tty:true, AttachStdin:true, Cmd:[]string{"bash"}, AttachStdout:true, AttachStderr:true, },nil,nil,"") if err := dockerClient.ContainerStart(ctx,container.ID,types.ContainerStartOptions{});err != nil{ log.Error("error when start container", err) return } idResponse, err :=dockerClient.ContainerExecCreate(ctx,container.ID,types.ExecConfig{ Cmd:[]string{"echo","hello"}, Tty:true, AttachStderr:true, AttachStdout:true, AttachStdin:true, Detach:true, }) if err := dockerClient.ContainerExecStart(ctx,idResponse.ID,types.ExecStartCheck{ }); err != nil{ log.Error("error when exec start ", err) } reader, err :=dockerClient.ContainerLogs(ctx,container.ID,types.ContainerLogsOptions{ ShowStdout:true, ShowStderr:true, }) if err != nil{ log.Error("error when containerLogs",err) } go io.Copy(os.Stdout,reader) &lt;- make(chan struct{}) </code></pre> <p>}</p> <p>as you can see, I create an new exec process, exec a new cmd called "echo hello", I want to get output from running container and show in my golang console. but not working, could you help me to solve? I try so many ways but not worked.</p> <p>and I also try to remove <code>dockerClient.ContainerLogs</code> block, replace with</p> <pre><code>conn, err :=dockerClient.ContainerAttach(ctx,container.ID,types.ContainerAttachOptions{ Stdout:true, Stderr:true, Stdin:true, Stream:true, Logs:true, }) go io.Copy(os.Stdout,conn.Reader) </code></pre> <p>but still cannot get logs from container. When I run above code, my console is empty, expected result is have "hello" in my console.</p> </div>

jenkins容器中使用docker,提示权限错误。

我按照官网的步骤: 创建容器 sudo docker run -u root -d --rm -p 8080:8080 -v jenkins-data:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueocean 然而进入容器还是报了如下错误 Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.39/containers/json: dial unix /var/run/docker.sock: connect: permission denied ![图片说明](https://img-ask.csdn.net/upload/201910/15/1571124630_534565.png)

无法弄清楚如何使用Docker容器进行交叉编译

<div class="post-text" itemprop="text"> <p>I am trying to cross compile some Go code to a windows target (based on this guide <a href="https://hub.docker.com/_/golang/" rel="nofollow">https://hub.docker.com/_/golang/</a>):</p> <pre><code>$ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp -e GOOS=windows -e GOARCH=386 golang:1.5 go get github.com/gorilla/websocket &amp;&amp; go build -v conn.go:8:2: cannot find package "github.com/gorilla/websocket" in any of: /usr/lib/go/src/github.com/gorilla/websocket (from $GOROOT) /home/mark/devel/gocode/src/github.com/gorilla/websocket (from $GOPATH) </code></pre> <p>I try to compile this: <a href="https://github.com/gorilla/websocket/tree/master/examples/chat" rel="nofollow">https://github.com/gorilla/websocket/tree/master/examples/chat</a>) ...but I can not figure out the correct command line :(</p> </div>

使用docker下载镜像失败

使用虚拟机中的centos7上的docker下载镜像时老是不行![图片说明](https://img-ask.csdn.net/upload/201910/21/1571661514_903235.png) [root@localhost ~]# docker pull nginx Using default tag: latest Trying to pull repository docker.io/library/nginx ... Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

ubuntu下,docker启动问题,在使用service docker start之后提示 Starting Docker: docker 但是并没有启动成功

ubuntu下,docker启动问题,在使用service docker start之后提示 Starting Docker: docker 但是并没有启动成功。在docker version里面只有client 没有service ![图片说明](https://img-ask.csdn.net/upload/202005/22/1590119129_126325.png) 在使用各种命令的时候出现Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? 我已经启动了docker 为什么还会出现这种问题? 我去查看了docker.sock 里面是空的。 怎么解决该问题!!!

使用golang docker API模拟docker run

<div class="post-text" itemprop="text"> <p>How can I achieve the equivalent of</p> <pre><code>sudo docker run -it --rm --name my-python-container -v "$PWD":/usr/src/myapp -w /usr/src/myapp python:2-slim python test.py </code></pre> <p>using the Docker API for Golang?</p> <p>Either <a href="https://github.com/fsouza/go-dockerclient" rel="nofollow">https://github.com/fsouza/go-dockerclient</a> or <a href="https://github.com/samalba/dockerclient" rel="nofollow">https://github.com/samalba/dockerclient</a> is fine.</p> </div>

mac 安装docker以后无法使用命令行

求解 为什么:mac 安装了docker以后在命令行界面无法使用docker命令。 ![图片说明](https://img-ask.csdn.net/upload/201805/30/1527676116_206735.jpeg)

我如何获得docker build登录下载进度标准输出

<div class="post-text" itemprop="text"> <blockquote> <p>FROM centos:6.7</p> <p>RUN ls -al</p> <p>WORKDIR /</p> <p>CMD "echo hi"</p> </blockquote> <p>this is simple Dockerfile </p> <p>I will create an image with this dockerfile and i'm not use shell cmd</p> <p>i'm using golang "exec" package and here is code</p> <pre><code>func execCommand(buildCmd string) { cmdArgs := strings.Fields(buildCmd) cmd := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...) cmdReader, _ := cmd.StdoutPipe() cmdReaderErr, _ := cmd.StderrPipe() scanner := bufio.NewScanner(cmdReader) scannerErr := bufio.NewScanner(cmdReaderErr) cmd.Start() go func() { for scanner.Scan() { fmt.Println("docker build out | ", scanner.Text()) } if scannerErr.Scan() { fmt.Print("docker build out err | ", scannerErr.Text()) } fmt.Println("end end end end ") }() } </code></pre> <p>this code is work well but here's the problem</p> <blockquote> <ol> <li><p>docker build out | Sending build context to Docker daemon 30.36MB</p></li> <li><p>docker build out | Step 1/4 : FROM centos:6.7</p></li> <li><p>docker build out | 6.7: Pulling from library/centos</p></li> <li><p>docker build out | cbddbc0189a0: Pulling fs layer</p></li> </ol> </blockquote> <p>4 line Pulling fs layer has can't change download progress bar</p> <p>and suddenly showing next line</p> <blockquote> <ol> <li><p>docker build out | Sending build context to Docker daemon 30.36MB</p></li> <li><p>docker build out | Step 1/4 : FROM centos:6.7</p></li> <li><p>docker build out | 6.7: Pulling from library/centos</p></li> <li><p>docker build out | cbddbc0189a0: Pulling fs layer</p></li> <li><p>docker build out | cbddbc0189a0: Verifying Checksum</p></li> <li><p>docker build out | cbddbc0189a0: Download complete</p></li> <li><p>docker build out | cbddbc0189a0: Pull complete</p></li> <li><p>docker build out | Digest: sha256:4c952fc7d30ed134109c769387313ab864711d1bd8b4660017f9d27243622df1</p></li> <li><p>docker build out | Status: Downloaded newer image for centos:6.7</p></li> </ol> </blockquote> <p>this is shell command docker build log</p> <blockquote> <p>docker build -t test:v1 .</p> <p>Sending build context to Docker daemon 30.36MB</p> <p>Step 1/4 : FROM centos:6.7</p> <p>6.7: Pulling from library/centos</p> <p>cbddbc0189a0: Downloading [===============&gt; ] 20.92MB/67.81MB</p> </blockquote> <p>golang stdout dosen't show Downloading [===============&gt; ] 20.92MB/67.81MB</p> <p>how can i show this stdout?</p> </div>

使用Docker时在Goland中配置GOROOT

<div class="post-text" itemprop="text"> <p>I am building a Go project with Docker in the new GoLand IDE. Unfortunately, I am not able to cofigure my <code>GOROOT</code> correctly, making it not possible to use the GoLand futures to the max.</p> <p>I have the following dockerfile:</p> <pre><code>FROM golang:1.9.3 # allows app_env to be set during build (defaults to empty string) ARG app_env # sets an environment variable to app_env argument, this way the variable will persist in the container for use in code ENV APP_ENV $app_env COPY ./ /go/src/github.com/Name/ProjectName/ WORKDIR /go/src/github.com/Name/ProjectName/app # install all dependencies RUN go get ./... # build the binary RUN go build # Put back once we have an application RUN app EXPOSE 8080 </code></pre> <p>I now execute my project as follows: </p> <ol> <li><code>docker build -t project-name .</code></li> <li><code>docker run -it -v ~/project-dir:/go/src/github.com/Name/ProjectName/app</code></li> </ol> <p>This works, however, I cannot find how I can configure GoLand to use the path on my Docker image <code>usr/local/go/bin</code> for my GoRoot, is that even possible in GoLand? (If not, why even bother adding 'docker support'?) </p> </div>

无法使用Docker存储库中供应商目录中的软件包

<div class="post-text" itemprop="text"> <p>I am trying to create a container with docker's go api. I want to expose a port using <code>container.Config.ExposedPorts</code> in <code>ContainerCreate()</code>API. Below is the code</p> <pre><code>package main import ( "fmt" "context" "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" "github.com/docker/go-connections/nat" ) func main() { ctx := context.Background() cli, err := client.NewClientWithOpts(client.WithVersion("1.38")) if err != nil { fmt.Println("Failed to get container envoronment", err) } resp, err := cli.ContainerCreate(ctx, &amp;container.Config{ Image: "hyperledger/fabric-ca", Cmd: []string{"/bin/sh", "-c", "fabric-ca-server start -b admin:adminpw"}, Env: []string{"FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server", "FABRIC_CA_SERVER_CA_NAME=ca.example.com"}, ExposedPorts: nat.PortSet{"22/tcp":struct{}{},}, }, nil, nil, "ca.example.com") if err != nil { fmt.Println(" failed to create container, err:", err) } else { fmt.Println(" Container ID :", resp.ID, "warning:", resp.Warnings, "err:", err) } } </code></pre> <p>when I compile I get the below error</p> <pre><code>vignesh@vignesh-ThinkPad-E470 ~/go-book/src/github.com/my_fabric $ go build asd.go asd.go:8:9: cannot find package "github.com/docker/go-connections/nat" in any of: /home/vignesh/go-book/src/github.com/my_fabric/vendor/github.com/docker/go-connections/nat (vendor tree) /usr/local/go/src/github.com/docker/go-connections/nat (from $GOROOT) /home/vignesh/go-book/src/github.com/docker/go-connections/nat (from $GOPATH) </code></pre> <p>As package <code>"github.com/docker/go-connections/nat"</code> is in a vendor directory at <code>"github.com/docker/docker/vendor/github.com/docker/go-connections/nat"</code>, I then created a vendor directory in my working directory and copied contents of <code>github.com/docker/docker/vendor/github.com/docker/go-connections/nat</code> to <code>github.com/my_fabric/vendor/go-connections/nat</code> and used <code>"github.com/my_fabric/go-connections/nat"</code> in import rather than <code>"github.com/docker/go-connections/nat"</code>. But I got the following error.</p> <pre><code>vignesh@vignesh-ThinkPad-E470 ~/go-book/src/github.com/my_fabric $ go build asd.go # command-line-arguments ./asd.go:25:29: cannot use "github.com/my_fabric/vendor/github.com/my_fabric/go-connections/nat".PortSet literal (type "github.com/my_fabric/vendor/github.com/my_fabric/go-connections/nat".PortSet) as type "github.com/docker/docker/vendor/github.com/docker/go-connections/nat".PortSet in field value </code></pre> <p>Basically I want to use packages which is in vendor directory in docker's repository. Kindly help :)</p> </div>

打算使用Docker客户端API测试方法的接口上的类型错误

<div class="post-text" itemprop="text"> <p>I'm refactoring a program I wrote so I can properly write tests for it. One of the first methods I'd like to test is a method that uses <a href="https://github.com/docker/docker/tree/master/client" rel="nofollow noreferrer">Docker's client API</a> to see if a certain image exists on a Docker host.</p> <p>To be able to test this method, I created an interface that matches <code>client.ImageList</code>'s <a href="https://godoc.org/github.com/docker/docker/client#Client.ImageList" rel="nofollow noreferrer">signature</a>:</p> <pre><code>type ImageLister interface { ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error) } </code></pre> <p>I also changed the method to test to take an <code>ImageLister</code> as argument, so I can pass in an <code>ImageLister</code> implementation specific to my tests.</p> <p>However, in my actual code, where I pass in the "real" Docker client to the method to test, the following compilation error occurs:</p> <blockquote> <p>ImageExists: *client.Client does not implement ImageLister (wrong type for ImageList method) have ImageList("github.com/docker/docker/vendor/golang.org/x/net/context".Context, types.ImageListOptions) ([]types.ImageSummary, error) want ImageList("context".Context, types.ImageListOptions) ([]types.ImageSummary, error)</p> </blockquote> <p>How can I resolve this? Or is my approach bad anyway, and should I go a different route?</p> <p>edit: The following program reproduces the issue I'm encountering.</p> <pre><code>package main import ( "context" "github.com/docker/docker/api/types" "github.com/docker/docker/client" ) type ImageLister interface { ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error) } func main() { client, err := client.NewEnvClient() defer client.Close() ImageExists(context.TODO(), client, "foo") } func ImageExists(ctx context.Context, lister ImageLister, image string) (bool, error) { return true, nil } </code></pre> </div>

无法使用Docker为Golang应用创建映像

<div class="post-text" itemprop="text"> <p>I try to create an image for my Golang application, but Docker just writes:</p> <pre><code>Step 7/9 : RUN go install ./accounting/server ---&gt; Running in f998ba6a5efb can't load package: package grpcProjects/multiService/accounting/server: cannot find package "grpcProjects/multiService/accounting/server" in any of: /usr/local/go/src/grpcProjects/multiService/accounting/server (from $GOROOT) /go/src/grpcProjects/multiService/accounting/server (from $GOPATH) </code></pre> <p>My Dockerfile:</p> <pre><code>FROM golang:1.10.4 ADD . /go/src/grpcProjects/multiService WORKDIR /go/src/grpcProjects/multiService RUN go get github.com/golang/protobuf/proto RUN go get golang.org/x/net/context RUN go get google.golang.org/grpc RUN go install ./accounting/server ENTRYPOINT [ "/go/bin/server" ] EXPOSE 8080 </code></pre> <p>Project structure:</p> <p><a href="https://i.stack.imgur.com/U9Eei.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U9Eei.png" alt="enter image description here"></a></p> <p>How to solve this problem?</p> </div>

Go应用程序失败并在使用docker-compose运行时退出,但可与docker run命令配合使用

<div class="post-text" itemprop="text"> <p>I am running all of these operations on a remove server that is a <strong>VM running Ubuntu 16.04.5 x64</strong>.</p> <p>My Go project's Dockerfile looks like:</p> <pre><code>FROM golang:latest ADD . $GOPATH/src/example.com/myapp WORKDIR $GOPATH/src/example.com/myapp RUN go build #EXPOSE 80 #ENTRYPOINT $GOPATH/src/example.com/myapp/myapp ENTRYPOINT ./myapp #CMD ["./myapp"] </code></pre> <p>When I run the docker container using <code>docker-compose up -d</code>, the Go application exits and I see this in the docker logs:</p> <blockquote> <p>myapp_1 | /bin/sh: 1: ./myapp: Exec format error docker_myapp_1 exited with code 2</p> </blockquote> <p>If I locate the image using <code>docker images</code> and run the image like:</p> <pre><code> docker run -it 75d4a95ef5ec </code></pre> <p>I can see that my golang applications runs just fine:</p> <blockquote> <p>viper environment is: development HTTP server listening on address: ":3005"</p> </blockquote> <p>When I googled for this error some people suggested compiling with some special flags but I am running this container on the same Ubuntu host so I am really confused why this isn't working using docker.</p> <p>My docker-compose.yml looks like:</p> <pre><code>version: "3" services: openresty: build: ./openresty ports: - "80:80" - "443:443" depends_on: - myapp env_file: - '.env' restart: always myapp: build: ../myapp volumes: - /home/deploy/apps/myapp:/go/src/example.com/myapp ports: - "3005:3005" depends_on: - db - redis - memcached env_file: - '.env' redis: image: redis:alpine ports: - "6379:6379" volumes: - "/home/deploy/v/redis:/data" restart: always memcached: image: memcached ports: - "11211:11211" restart: always db: image: postgres:9.4 volumes: - "/home/deploy/v/pgdata:/var/lib/postgresql/data" restart: always </code></pre> </div>

Docker-无法从外部访问docker端口

<div class="post-text" itemprop="text"> <p>So i created a new EC2 Instance and installed docker on it.</p> <p>I deployed code from ( <a href="https://github.com/commonsearch/cosr-front/blob/master/INSTALL.md" rel="nofollow">https://github.com/commonsearch/cosr-front/blob/master/INSTALL.md</a> ) and followed install instructions.</p> <p>Install was successfull and i started the server:</p> <pre><code>[ec2-user@ip-172-30-0-127 cosr-front]$ make docker_devserver docker run -e DOCKER_HOST --rm -v "/home/ec2-user/cosr-front:/go/src/github.com/commonsearch/cosr-front:rw" -w /go/src/github.com/commonsearch/cosr-front -p 9700:9700 -i -t commonsearch/local-front make devserver mkdir -p build go build -o build/cosr-front.bin ./server GODEBUG=gctrace=1 COSR_DEBUG=1 ./build/cosr-front.bin 2016/05/28 16:32:38 Using Docker host IP: 172.17.0.1 2016/05/28 16:32:38 Server listening on 127.0.0.1:9700 - You should open http://127.0.0.1:9700 in your browser! </code></pre> <p>Well, now when i want to access it from outside, i cant! Not even curl the local server.</p> <p>When i run <code>docker ps</code> it gives me correct port forwarding: </p> <pre><code>[ec2-user@ip-172-30-0-127 ~]$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1a9f77e1eeb1 commonsearch/local-front "make devserver" 4 minutes ago Up 4 minutes 0.0.0.0:9700-&gt;9700/tcp stoic_hopper 9ff00fe3e70d commonsearch/local-elasticsearch-devindex "/docker-entrypoint.s" 4 minutes ago Up 4 minutes 0.0.0.0:39200-&gt;9200/tcp, 0.0.0.0:39300-&gt;9300/tcp kickass_wilson </code></pre> <p>These are my docker images:</p> <pre><code>REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE &lt;none&gt; &lt;none&gt; 3e205118cd3f 17 minutes ago 853.3 MB &lt;none&gt; &lt;none&gt; 1d233da1fa59 2 hours ago 955.7 MB debian jessie ce58426c830c 4 days ago 125.1 MB commonsearch/local-front latest 30de7ab48d43 7 weeks ago 1.024 GB commonsearch/local-elasticsearch-devindex latest b1156ada5a24 11 weeks ago 383.2 MB commonsearch/local-elasticsearch latest 808e72f49b4a 3 months ago 355.2 MB </code></pre> <p>I have tryed disabling ipv6 and all kind of nonsense google offered me, but without success.</p> <p>Any ideas ?</p> <p>EDIT:</p> <p>Also, if i enter the docker container for frontend( using docker exec ), then I CAN PING AND CULR the frontend.</p> <p>But i cant from the outside( nor ssh, not from my home pc using browser ).</p> <p>Also my docker version:</p> <pre><code>Client: Version: 1.9.1 API version: 1.21 Go version: go1.4.2 Git commit: a34a1d5/1.9.1 Built: OS/Arch: linux/amd64 Server: Version: 1.9.1 API version: 1.21 Go version: go1.4.2 Git commit: a34a1d5/1.9.1 Built: OS/Arch: linux/amd64 </code></pre> </div>

Beego-使用docker-compose实施中的端口号,而不是使用app.conf中的端口号

<div class="post-text" itemprop="text"> <p>I am trying to run the beego application using docker with the help of docker-compose. I am able access the demo application in <a href="http://localhost:8081" rel="nofollow noreferrer">http://localhost:8081</a> URL after running <code>docker-compose up</code>.</p> <p><strong>docker-compose.yml</strong></p> <pre><code>version: "2" services: app: build: . volumes: - .:/go/src/hello ports: - "8080:8080" working_dir: /go/src/hello command: bee run </code></pre> <p><strong>Dockerfile</strong></p> <pre><code>FROM golang:1.10 ## Install beego and the bee dev tool RUN go get github.com/astaxie/beego &amp;&amp; go get github.com/beego/bee </code></pre> <p><strong>app.conf</strong> from beego framework</p> <pre><code>appname = hello httpport = 8081 runmode = dev </code></pre> <p>How can I overwrite the <code>httpport</code>(8081) in <code>app.conf</code> using <code>ports</code>(8080) number used in <code>app</code> from <code>docker-compose.yml</code>. After running <code>docker-compose up</code> application runs in port 8081 not in 8080. How can I solve this?</p> </div>

2019 Python开发者日-培训

2019 Python开发者日-培训

150讲轻松搞定Python网络爬虫

150讲轻松搞定Python网络爬虫

设计模式(JAVA语言实现)--20种设计模式附带源码

设计模式(JAVA语言实现)--20种设计模式附带源码

YOLOv3目标检测实战:训练自己的数据集

YOLOv3目标检测实战:训练自己的数据集

java后台+微信小程序 实现完整的点餐系统

java后台+微信小程序 实现完整的点餐系统

三个项目玩转深度学习(附1G源码)

三个项目玩转深度学习(附1G源码)

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

2019 AI开发者大会

2019 AI开发者大会

玩转Linux:常用命令实例指南

玩转Linux:常用命令实例指南

一学即懂的计算机视觉(第一季)

一学即懂的计算机视觉(第一季)

4小时玩转微信小程序——基础入门与微信支付实战

4小时玩转微信小程序——基础入门与微信支付实战

Git 实用技巧

Git 实用技巧

Python数据清洗实战入门

Python数据清洗实战入门

使用TensorFlow+keras快速构建图像分类模型

使用TensorFlow+keras快速构建图像分类模型

实用主义学Python(小白也容易上手的Python实用案例)

实用主义学Python(小白也容易上手的Python实用案例)

程序员的算法通关课:知己知彼(第一季)

程序员的算法通关课:知己知彼(第一季)

MySQL数据库从入门到实战应用

MySQL数据库从入门到实战应用

机器学习初学者必会的案例精讲

机器学习初学者必会的案例精讲

手把手实现Java图书管理系统(附源码)

手把手实现Java图书管理系统(附源码)

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

.net core快速开发框架

.net core快速开发框架

玩转Python-Python3基础入门

玩转Python-Python3基础入门

Python数据挖掘简易入门

Python数据挖掘简易入门

微信公众平台开发入门

微信公众平台开发入门

程序员的兼职技能课

程序员的兼职技能课

Windows版YOLOv4目标检测实战:训练自己的数据集

Windows版YOLOv4目标检测实战:训练自己的数据集

HoloLens2开发入门教程

HoloLens2开发入门教程

微信小程序开发实战

微信小程序开发实战

Java8零基础入门视频教程

Java8零基础入门视频教程

相关热词 c#跨线程停止timer c#批量写入sql数据库 c# 自动安装浏览器 c#语言基础考试题 c# 偏移量打印是什么 c# 绘制曲线图 c#框体中的退出函数 c# 按钮透明背景 c# idl 混编出错 c#在位置0处没有任何行
立即提问