普通网友 2017-02-09 08:12
浏览 90
已采纳

在Docker容器(Ubuntu)的Windows中创建的Run Go应用程序

I created very simple application that put to output some text.

My development environment is Windows + Docker for Windows. I created ubuntu container and after build my application in Windows for ubuntu

set GOARCH=amd64
set GOOS=linux
go build -o "myapp"

Then I copy 'myapp' file to shared folder and see it in shared folder of my container. After I try to run it inside container but there is an error

enter image description here

Why can't I run it? Was it built incorrectly or do I try to execute it in some wrong way?

In windows I have this output when I run my exe file and I want something the same in Ubuntu.

enter image description here

UPDATE As suggested I try ./myapp and there is Exec format error

enter image description here

  • 写回答

1条回答 默认 最新

  • doumengyin0491 2017-02-09 08:28
    关注

    On ubuntu and other linux systems, just myapp will try to find myapp from the PATH environment variable. To look specifically for an executable inside the current directory, you need to use:

    ./myapp
    

    Or use the complete path:

    /__shared/myapp
    

    UPDATE: for this to work, your file need to be executable. You can verify it using ls -l:

    ls -l
    -rwxrwxr-x  1 user user    0 Feb  9 09:45 myapp
    

    If you don't see at least one 'x' in the first column, you need to run:

    chmod +x myapp
    

    See understanding-linux-file-permissions for more information on the subject.

    UPDATE: the error cannot execute binary file: Exec format error' could come from:

    • a mismatch between the system architecture and the file --> ensure your ubuntu machine is a 64-bit version and compare the output of uname -a and file myapp
    • according to this thread, running a file inside the shared folder of the VM (with windows host) can cause trouble --> try to copy myapp outside the shared folder
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条