New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerize Wechaty for easy start #66

Closed
huan opened this Issue Oct 28, 2016 · 36 comments

Comments

6 participants
@huan
Copy link
Member

huan commented Oct 28, 2016

UPDATE 4th Nov 2016

All done. Please goto wiki: Docker


The Problem

to setup running environment for wechaty is not easy for everyone. sometimes even myself have trouble with that.

A Solution

so it must be fully dockerized! after dockerize, we can use wechaty like the following:

$ cat > mybot.ts
// have to use absolute path `'/wechaty'` to make `ts-node` happy. will fix it later.
// import Wechaty from '/wechaty'

import { Wechaty } from 'wechaty' // just from 'wechaty' is OK

const bot = Wechaty.instance()
console.log(bot.version())
^D

$ alias wechaty='docker run \
    -t -i --rm \
    -e WECHATY_LOG="$WECHATY_LOG" \
    --volume="$(pwd)":/bot \
    --name=wechaty \
    zixia/wechaty \
'

$ wechaty mybot.ts

see? death easy to use!

Docker options explanation

  1. -t : Allocate a pseudo-TTY
  2. -i : Keep STDIN open even if not attached
  3. --rm : Automatically remove the container when it exits
  4. -e WECHATY_LOG="$WECHATY_LOG" : Pass the environment variable WECHATY_LOG into the container
  5. --volume="$(pwd)":/bot : Bind current directory(replaced by "$(pwd)") to '/bot' inside the container, by mounting the volume
  6. --name=wechaty : Assign wechaty as the container name
  7. zixia/wechaty : Image name on docker hub, here's our zixia/wechaty
  8. mybot.ts : File contains code wrote by you, should be placed in current directory ./

Reference

  1. chromium require libgconf-2-4 package: electron/electron#1518
  2. Microcontainers – Tiny, Portable Docker Containers

Memo

this issue will record the process of Wechaty Docker and will be used for reference from other issues related.

@huan huan changed the title Dockerize Wechaty for easy use Dockerize Wechaty for easy start Oct 28, 2016

huan added a commit that referenced this issue Oct 28, 2016

@JasLin

This comment has been minimized.

Copy link
Contributor

JasLin commented Oct 28, 2016

@zixia

docker: Error response from daemon: create .: "." includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed.

docker do not allow "." present in local volumn name (at ubuntu ,Docker version 1.12.3)

use $(pwd) may be more compatible:

 docker run -t -i --rm -v $(pwd):/app zixia/wechaty bot.ts
@JasLin

This comment has been minimized.

Copy link
Contributor

JasLin commented Oct 28, 2016

it seems wechaty module wasn't installed in docker .


 __        __        _           _          
 \ \      / /__  ___| |__   __ _| |_ _   _  
  \ \ /\ / / _ \/ __| '_ \ / _` | __| | | | 
   \ V  V /  __/ (__| | | | (_| | |_| |_| | 
    \_/\_/ \___|\___|_| |_|\__,_|\__|\__, | 
                                     |___/  
____________________________________________________
              https://www.wechaty.io
  ____                            _   _             
 / ___|___  _ __  _ __   ___  ___| |_(_)_ __   __ _ 
| |   / _ \| '_ \| '_ \ / _ \/ __| __| | '_ \ / _` |
| |__| (_) | | | | | | |  __/ (__| |_| | | | | (_| |
 \____\___/|_| |_|_| |_|\___|\___|\__|_|_| |_|\__, |
                                              |___/ 
  ____ _           _   ____        _       
 / ___| |__   __ _| |_| __ )  ___ | |_ ___ 
| |   | '_ \ / _` | __|  _ \ / _ \| __/ __|
| |___| | | | (_| | |_| |_) | (_) | |_\__ \
 \____|_| |_|\__,_|\__|____/ \___/ \__|___/


Starting Wechaty ... v#git[c30c400 doc dockerfile #66]

Executing ts-node /app/bot.ts

/wechaty/node_modules/ts-node/dist/index.js:160
                    throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset));
                    ^
TSError: ⨯ Unable to compile TypeScript
../app/bot.ts (1,21): Cannot find module 'wechaty'. (2307)
@huan

This comment has been minimized.

Copy link
Member Author

huan commented Oct 28, 2016

thanks for trying that!

please try to use import wechaty from '/wechaty' instead, have fun!

BTW: it's still a issue stage, u come so early! :)

I will update this issue when ready, and any suggestion is welcome. :)

@huan huan added this to the v0.5 milestone Oct 28, 2016

@huan huan self-assigned this Oct 28, 2016

@JasLin

This comment has been minimized.

Copy link
Contributor

JasLin commented Oct 29, 2016

haha, i am early adopter:)

@sleedata

This comment has been minimized.

Copy link

sleedata commented Oct 31, 2016

Hi @zixia,

I have no troubles running: "docker run -t -i --rm zixia/wechaty run demo" based on [https://github.com//issues/65]. However, when change the above command to run the local ding-dong-bot.ts using: "docker run -t -i --rm zixia/wechaty ding-dong-bot.ts" it says file not found. I moved the ding-dong-bots.ts from examples/ to ./. It says file not found..

`
[ec2-user@ip-172-31-53-19 wechaty]$ docker run -t -i --rm --name=wechaty zixia/wechaty ding-dong-bot.ts

Starting Wechaty ... v#git[3b91cfc docker runner support install dependence modules automaticly from package.json by yarn, with cache]

ERROR: can not found bot file: ding-dong-bot.ts
[ec2-user@ip-172-31-53-19 wechaty]$ ls ding-dong-bot.ts
ding-dong-bot.ts
[ec2-user@ip-172-31-53-19 wechaty]$
`

@huan

This comment has been minimized.

Copy link
Member Author

huan commented Nov 1, 2016

hi @sleedata, thank you for trying this.

you are almost there, and after take the following two steps, you should be no problem running with wechaty docker with your local file:

  1. you need to bind the volume of /bot by adding this arg: --volume="$PWD":/bot, which is required to run local files in the container.

  2. you need to modify ding-dong-bot.ts file to import everything from /wechaty(will change to just wechaty later) from ../../ like the following diff show you:

    - import Wechaty from '../../'
    + // Must use absolute path `'/wechaty'` to make `ts-node` happy. will fix later.
    + import Wechaty from '/wechaty'

One more thing: if your code has any module dependence, you must place the package.json file in the same directory, to let wechaty docker install all the dependency for you. (what wechaty will do is just run yarn command in the current directory)

summary: after modifying the import path, this command should work for you:

$ docker run \
    -t -i --rm \
    -e WECHATY_LOG=warn \
    --volume="$PWD":/bot \
    --name=wechaty \
    zixia/wechaty \
    ding-dong-bot.ts

please let me know if it works, good luck!

huan added a commit that referenced this issue Nov 1, 2016

@sleedata

This comment has been minimized.

Copy link

sleedata commented Nov 1, 2016

Now, it's a different error. I'm starting to wonder if it's the AMI Linux distro that's incompatible? Should have use Ubuntu.
Here's the error I now have:
`Hope you like it, and you are very welcome to upgrade me for more super powers!

Please wait... I'm trying to login in...

(node:41) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
ERR PuppetWebBrowser init() exception: The specified executable path does not exist: /root/node_modules/chromedriver/lib/chromedriver/chromedriver
WARN PuppetWebBrowser quit() exception: Cannot read property 'close' of undefined
WARN PuppetWebBrowser driver.quit() exception: Cannot read property 'close' of undefined
ERR PuppetWeb initBrowser() exception: The specified executable path does not exist: /root/node_modules/chromedriver/lib/chromedriver/chromedriver
ERR PuppetWeb init() exception: Error: The specified executable path does not exist: /root/node_modules/chromedriver/lib/chromedriver/chromedriver
at ServiceBuilder. (/root/node_modules/selenium-webdriver/remote/index.js:325:13)
at ServiceBuilder (/root/node_modules/selenium-webdriver/chrome.js:199:5)
at BrowserDriver. (/root/src/puppet-web/browser-driver.ts:86:21)
at Generator.next ()
at /root/src/puppet-web/browser-driver.ts:7:65
at __awaiter (/root/src/puppet-web/browser-driver.ts:3:12)
at BrowserDriver.getChromeDriver (/root/src/puppet-web/browser-driver.ts:65:16)
at BrowserDriver. (/root/src/puppet-web/browser-driver.ts:59:34)
at Generator.next ()
at /root/src/puppet-web/browser-driver.ts:7:65
WARN PuppetWebWatchdog onFeed() is disabled because target state is dead or state is inprocess
WARN PuppetWeb quit() without a bridge
WARN PuppetWebBrowser quit() exception: Cannot read property 'close' of undefined
WARN PuppetWebBrowser driver.quit() exception: Cannot read property 'close' of undefined
ERR Wechaty init() exception: The specified executable path does not exist: /root/node_modules/chromedriver/lib/chromedriver/chromedriver
ERR Bot init() fail: Error: The specified executable path does not exist: /root/node_modules/chromedriver/lib/chromedriver/chromedriver
WARN PuppetWeb quit() without a bridge
[ec2-user@ip-172-31-53-19 wechaty]$
`

@huan

This comment has been minimized.

Copy link
Member Author

huan commented Nov 1, 2016

Sorry for that.

It is not the fault of AMI Linux distro; it more likes a bug in wechaty docker starter script.

I have no idea why PuppetWebBrowser want to find chromedriver in /root/node_modules/chromedriver/lib/chromedriver/chromedriver on your server. The chromedriver should already exist in /wechaty/node_modules.

Can you paste your package.json and your mybot.ts file (and other information, if any) here? Then I can try to reproduce this error.

huan added a commit that referenced this issue Nov 1, 2016

huan added a commit that referenced this issue Nov 1, 2016

@sleedata

This comment has been minimized.

Copy link

sleedata commented Nov 1, 2016

Hi @zixia ,

No worries. I'm willing to help and contribute. It's a new learning process for me as well (at least in this bot domain). As requested, i've paste those files. It's the same ding-dong-bot.ts and i re-use the same package.json clone from this repo. I validated that chromedriver is under node_modules. Let me know how I can help.

From what I can see, it's referencing from root/node_modules/chromedriver/lib/chromedriver/chromedriver, as opposed to /node_modules/chromedriver

Download Here:requested.zip

@sleedata

This comment has been minimized.

Copy link

sleedata commented Nov 1, 2016

@zixia, May I know what variant of Linux are you using?

@huan

This comment has been minimized.

Copy link
Member Author

huan commented Nov 1, 2016

@sleedata what we are using now is a standard Debian Linux(official node image from docker hub).

I'm on my way to switch wechaty docker to Alpine Linux, which we can expect to get the benefit of about 1/3 size(less than 180MB). In contrast, now wechaty docker image is 430MB after compressed, 1.1GB totally.

so if you pull zixia/wechaty tomorrow, it should be the Alpine Linux image.

However, you should not feel any difference between the Linux Distribution switch. You just set and run. And I will test your code in new docker image tomorrow.

The switch detail: 482f343

@sleedata

This comment has been minimized.

Copy link

sleedata commented Nov 1, 2016

@zixia Many thanks. I'll wait for your good news. :)

@huan

This comment has been minimized.

Copy link
Member Author

huan commented Nov 1, 2016

Alpine Linux version just published, with 159MB size, cheers!

Before

1.1GB/430MB(compressed)

After

422MB(uncompressed)

and the final size is:

159MB

60% off!

@sleedata

This comment has been minimized.

Copy link

sleedata commented Nov 1, 2016

@zixia, Many many thanks. It's working.... So happy... Now I can start writing some code.
谢谢你的帮助.

@huan

This comment has been minimized.

Copy link
Member Author

huan commented Nov 2, 2016

@sleedata Great!

And congratulations, for you are the first user of Alpine Wechaty Docker.

Please let me know if you have any suggestions, for improving the usability of wechaty.

Happy coding! :)

@JasLin

This comment has been minimized.

Copy link
Contributor

JasLin commented Nov 3, 2016

@zixia

error while running demo

Starting Wechaty ... v0.5.0                                                                                                                  

/bot                                                                                                                                         
Linking Wechaty Module ...                                                                                                                   
Executing ts-node /bot/mybot.ts                                                                                                              

/wechaty/node_modules/ts-node/dist/index.js:160                                                                                              
                    throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset));                                               
                    ^                                                                                                                        
TSError: ⨯ Unable to compile TypeScript                                                                                                      
../wechaty/src/io.ts (299,5): Type 'number' is not assignable to type 'Timer | null'. (2322)                                                 
  ____  _   _  ____   ____  _____ ____   ___  ____ _____                                                                                     
 | __ )| | | |/ ___| |  _ \| ____|  _ \ / _ \|  _ \_   _|                                                                                    
 |  _ \| | | | |  _  | |_) |  _| | |_) | | | | |_) || |                                                                                      
 | |_) | |_| | |_| | |  _ <| |___|  __/| |_| |  _ < | |                                                                                      
 |____/ \___/ \____| |_| \_\_____|_|    \___/|_| \_\|_|                                                                                      

Press ENTER to print diagnose output ...                                                                                                     

### 1. code of mybot.ts                                                                                                                      
import Wechaty from '/wechaty'                                                                                                               

const bot = Wechaty.instance()                                                                                                               
console.log(bot.version())### 2. directory structor of /bot                                                                                  
total 24                                                                                                                                     
drwxrwxr-x 2 1000 1000 4096 Nov  3 06:47 bot                                                                                                 
-rw-r--r-- 1 root root  341 Nov  1 11:52 demo.wechaty.json                                                                                   
-rw-rw-r-- 1 1000 1000 2270 Oct 29 04:42 ding-dong-bot.js                                                                                    
-rw-rw-r-- 1 1000 1000 2144 Nov  1 11:50 ding-dong-bot.ts                                                                                    
-rw-rw-r-- 1 1000 1000   89 Nov  3 06:52 mybot.ts                                                                                            
drwxr-xr-x 3 root root 4096 Nov  3 06:52 node_modules                                                                                        
### 3. package.json                                                                                                                          
cat: /bot/package.json: No such file or directory                                                                                            
zsh: command not found: bot.ts   
@huan

This comment has been minimized.

Copy link
Member Author

huan commented Nov 3, 2016

@JasLin your local docker image is outdated.

please run docker pull zixia/wechaty to update to the latest version.

should be ok because I just tested for you, it ran without any problem.

@JasLin

This comment has been minimized.

Copy link
Contributor

JasLin commented Nov 3, 2016

ok, i will try it later,thanks:)

@huan

This comment has been minimized.

Copy link
Member Author

huan commented Nov 3, 2016

@JasLin you are welcome. it seems Wechaty Docker is working well now.

with the latest version:

  1. we should write import { Wechaty } from 'wechaty' instead of '/wechaty'
  2. we should write javascript code(with filename .js) instead of typescript(.ts): const { Wechaty } = require('wechaty')

please let me know if there's any additional issue, thanks!

@huan huan closed this in 5d4ea6d Nov 3, 2016

@anjoah

This comment has been minimized.

Copy link

anjoah commented Jan 9, 2018

@zixia
hi, I have arrourd a problem ,with the when using docker version 17.11.0-ce, build 1caf76c..the below infomation:

cat mybot.js 

const { Wechaty } = require('wechaty')

Wechaty.instance() // Singleton
.on('scan', (url, code) => console.log(`Scan QrCode to login: ${code}\n${url}`))
.on('login',       user => console.log(`User ${user} logined`))
.on('message',  message => console.log(`Message: ${message}`))
.init()

 alias wechaty='docker run \
>     -t -i --rm \
>     -e WECHATY_LOG="$WECHATY_LOG" \
>     --volume="$(pwd)":/bot \
>     --name=wechaty \
>     zixia/wechaty \
> '
 wechaty mybot.js

 __        __        _           _          
 \ \      / /__  ___| |__   __ _| |_ _   _  
  \ \ /\ / / _ \/ __| '_ \ / _` | __| | | | 
   \ V  V /  __/ (__| | | | (_| | |_| |_| | 
    \_/\_/ \___|\___|_| |_|\__,_|\__|\__, | 
                                     |___/  
____________________________________________________
            https://www.chatie.io
  ____                            _   _             
 / ___|___  _ __  _ __   ___  ___| |_(_)_ __   __ _ 
| |   / _ \| '_ \| '_ \ / _ \/ __| __| | '_ \ / _` |
| |__| (_) | | | | | | |  __/ (__| |_| | | | | (_| |
 \____\___/|_| |_|_| |_|\___|\___|\__|_|_| |_|\__, |
                                              |___/ 
  ____ _           _   ____        _       
 / ___| |__   __ _| |_| __ )  ___ | |_ ___ 
| |   | '_ \ / _` | __|  _ \ / _ \| __/ __|
| |___| | | | (_| | |_| |_) | (_) | |_\__ \
 \____|_| |_|\__,_|\__|____/ \___/ \__|___/
                                           

Starting Wechaty v0.13.37 with Node.js v8.9.1 ...
ERROR: can not found bot file: mybot.js
  _____                _     _           _                 _   _              
 |_   _| __ ___  _   _| |__ | | ___  ___| |__   ___   ___ | |_(_)_ __   __ _  
   | || '__/ _ \| | | | '_ \| |/ _ \/ __| '_ \ / _ \ / _ \| __| | '_ \ / _` | 
   | || | | (_) | |_| | |_) | |  __/\__ \ | | | (_) | (_) | |_| | | | | (_| | 
   |_||_|  \___/ \__,_|_.__/|_|\___||___/_| |_|\___/ \___/ \__|_|_| |_|\__, | 
                                                                       |___/  

    Troubleshooting:

    1. Did you bind the current directory into container?

      check your `docker run ...` command, if there's no `volumn` arg,
      then you need to add it so that we can bind the volume of /bot:

        `--volume="$(pwd)":/bot`

      this will let the container visit your current directory.

    if you still have issue, please have a look at
      https://github.com/chatie/wechaty/issues/66
      and do a search in issues, that might be help.


 __        __        _           _          
 \ \      / /__  ___| |__   __ _| |_ _   _  
  \ \ /\ / / _ \/ __| '_ \ / _` | __| | | | 
   \ V  V /  __/ (__| | | | (_| | |_| |_| | 
    \_/\_/ \___|\___|_| |_|\__,_|\__|\__, | 
                                     |___/  
____________________________________________________
            https://www.chatie.io
  _____      _ _     _  
 | ____|_  _(_) |_  / | 
 |  _| \ \/ / | __| | | 
 | |___ >  <| | |_  | | 
 |_____/_/\_\_|\__| |_| 
                        
@huan

This comment has been minimized.

Copy link
Member Author

huan commented Jan 10, 2018

@anjoah We are using docker without any problems.

Please file a new issue for your problem if you still can not make it work.

@IdiosApps

This comment has been minimized.

Copy link
Contributor

IdiosApps commented Feb 1, 2018

In case anyone else installed Windows 10 Enterprise Edition (because Docker can't run on Home edition) and has this problem (can't find bot file) - make sure that your files are definitely .js/.ts!

I made three text files, naming them as mybot.js, test.ts, and data.json. I downloaded notepad++ and associated the .js file with np++, and then I saw that all 3 files were now associated with np++. I realised that these were actually like mybot.js.txt (3 .txt files). Windows was hiding the file extension (by default, after a fresh install).

Docker runs the code fine now.
mybot.js is in "C:\Users\James\wechaty", and I ran the provided line from PowerShell in the directory with those 3 files. This is the PS code: "docker run -ti --volume="$(pwd)":/bot --rm zixia/wechaty" mybot.js".

IdiosApps added a commit to IdiosApps/wechaty that referenced this issue Feb 1, 2018

Update entrypoint.sh
Added troubleshooting for new Windows installs (more info in my comment in issue Chatie#66).

huan added a commit that referenced this issue Feb 2, 2018

Add troubleshooting for hidden .txt files (Windows) (#1087)
* Update entrypoint.sh

Added troubleshooting for new Windows installs (more info in my comment in issue #66).

* Update entrypoint.sh

fix formatting (indentation) of w10 troubleshooting addition.
@SuperAL

This comment has been minimized.

Copy link

SuperAL commented Mar 14, 2018

@zixia I have the same problem as @anjoah

[root@centos-wechaty wechaty-bot]# ls
mybot.js  package.json  README.md
[root@centos-wechaty wechaty-bot]# docker run -t -i --rm --volume="$(pwd)":/bot zixia/wechaty mybot.js

 __        __        _           _          
 \ \      / /__  ___| |__   __ _| |_ _   _  
  \ \ /\ / / _ \/ __| '_ \ / _` | __| | | | 
   \ V  V /  __/ (__| | | | (_| | |_| |_| | 
    \_/\_/ \___|\___|_| |_|\__,_|\__|\__, | 
                                     |___/  
____________________________________________________
            https://www.chatie.io
  ____                            _   _             
 / ___|___  _ __  _ __   ___  ___| |_(_)_ __   __ _ 
| |   / _ \| '_ \| '_ \ / _ \/ __| __| | '_ \ / _` |
| |__| (_) | | | | | | |  __/ (__| |_| | | | | (_| |
 \____\___/|_| |_|_| |_|\___|\___|\__|_|_| |_|\__, |
                                              |___/ 
  ____ _           _   ____        _       
 / ___| |__   __ _| |_| __ )  ___ | |_ ___ 
| |   | '_ \ / _` | __|  _ \ / _ \| __/ __|
| |___| | | | (_| | |_| |_) | (_) | |_\__ \
 \____|_| |_|\__,_|\__|____/ \___/ \__|___/
                                           

Starting Wechaty v0.13.79 with Node.js v9.8.0 ...
ERROR: can not found bot file: mybot.js
  _____                _     _           _                 _   _              
 |_   _| __ ___  _   _| |__ | | ___  ___| |__   ___   ___ | |_(_)_ __   __ _  
   | || '__/ _ \| | | | '_ \| |/ _ \/ __| '_ \ / _ \ / _ \| __| | '_ \ / _` | 
   | || | | (_) | |_| | |_) | |  __/\__ \ | | | (_) | (_) | |_| | | | | (_| | 
   |_||_|  \___/ \__,_|_.__/|_|\___||___/_| |_|\___/ \___/ \__|_|_| |_|\__, | 
                                                                       |___/  

    Troubleshooting:

    1. Did you bind the current directory into container?

      check your `docker run ...` command, if there's no `volumn` arg,
      then you need to add it so that we can bind the volume of /bot:

        `--volume="$(pwd)":/bot`

      this will let the container visit your current directory.

    2. Are you sure your .js/.ts files aren't .js.txt/.ts.txt?

      this could be a problem on new Windows installs (file
      extensions hidden by default).

    if you still have issue, please have a look at
      https://github.com/chatie/wechaty/issues/66
      and do a search in issues, that might be help.


 __        __        _           _          
 \ \      / /__  ___| |__   __ _| |_ _   _  
  \ \ /\ / / _ \/ __| '_ \ / _` | __| | | | 
   \ V  V /  __/ (__| | | | (_| | |_| |_| | 
    \_/\_/ \___|\___|_| |_|\__,_|\__|\__, | 
                                     |___/  
____________________________________________________
            https://www.chatie.io
  _____      _ _     _  
 | ____|_  _(_) |_  / | 
 |  _| \ \/ / | __| | | 
 | |___ >  <| | |_  | | 
 |_____/_/\_\_|\__| |_| 
@huan

This comment has been minimized.

Copy link
Member Author

huan commented Mar 15, 2018

@SuperAL Can you reproduce it with a GitHub repository?

I would like to find out the reason of this issue but we have to be able to reproduce it first.

huan added a commit that referenced this issue Mar 15, 2018

@SuperAL

This comment has been minimized.

Copy link

SuperAL commented Mar 16, 2018

你可以从下面的操作看出来哪里有问题吗?

[alex@centos-wechaty ~]$ cd wechaty-bot
[alex@centos-wechaty wechaty-bot]$ ll
total 12
-rw-r--r--. 1 alex alex 326 Mar 14 03:53 mybot.js
-rw-rw-r--. 1 alex alex 444 Mar 14 03:07 package.json
-rw-rw-r--. 1 alex alex  13 Mar 14 03:07 README.md
[alex@centos-wechaty wechaty-bot]$ cat mybot.js
const { Wechaty } = require('wechaty') // import { Wechaty } from 'wechaty'

Wechaty.instance() // Singleton
.on('scan', (url, code) => console.log(`Scan QR Code to login: ${code}\n${url}`))
.on('login',       user => console.log(`User ${user} logined`))
.on('message',  message => console.log(`Message: ${message}`))
.start()
[alex@centos-wechaty wechaty-bot]$ docker run -ti --volume="$(pwd)":/bot --rm zixia/wechaty mybot.js

 __        __        _           _          
 \ \      / /__  ___| |__   __ _| |_ _   _  
  \ \ /\ / / _ \/ __| '_ \ / _` | __| | | | 
   \ V  V /  __/ (__| | | | (_| | |_| |_| | 
    \_/\_/ \___|\___|_| |_|\__,_|\__|\__, | 
                                     |___/  
____________________________________________________
            https://www.chatie.io
  ____                            _   _             
 / ___|___  _ __  _ __   ___  ___| |_(_)_ __   __ _ 
| |   / _ \| '_ \| '_ \ / _ \/ __| __| | '_ \ / _` |
| |__| (_) | | | | | | |  __/ (__| |_| | | | | (_| |
 \____\___/|_| |_|_| |_|\___|\___|\__|_|_| |_|\__, |
                                              |___/ 
  ____ _           _   ____        _       
 / ___| |__   __ _| |_| __ )  ___ | |_ ___ 
| |   | '_ \ / _` | __|  _ \ / _ \| __/ __|
| |___| | | | (_| | |_| |_) | (_) | |_\__ \
 \____|_| |_|\__,_|\__|____/ \___/ \__|___/
                                           

Starting Wechaty v0.13.79 with Node.js v9.8.0 ...
ERROR: can not found bot file: mybot.js
  _____                _     _           _                 _   _              
 |_   _| __ ___  _   _| |__ | | ___  ___| |__   ___   ___ | |_(_)_ __   __ _  
   | || '__/ _ \| | | | '_ \| |/ _ \/ __| '_ \ / _ \ / _ \| __| | '_ \ / _` | 
   | || | | (_) | |_| | |_) | |  __/\__ \ | | | (_) | (_) | |_| | | | | (_| | 
   |_||_|  \___/ \__,_|_.__/|_|\___||___/_| |_|\___/ \___/ \__|_|_| |_|\__, | 
                                                                       |___/  

    Troubleshooting:

    1. Did you bind the current directory into container?

      check your `docker run ...` command, if there's no `volumn` arg,
      then you need to add it so that we can bind the volume of /bot:

        `--volume="$(pwd)":/bot`

      this will let the container visit your current directory.

    2. Are you sure your .js/.ts files aren't .js.txt/.ts.txt?

      this could be a problem on new Windows installs (file
      extensions hidden by default).

    if you still have issue, please have a look at
      https://github.com/chatie/wechaty/issues/66
      and do a search in issues, that might be help.


 __        __        _           _          
 \ \      / /__  ___| |__   __ _| |_ _   _  
  \ \ /\ / / _ \/ __| '_ \ / _` | __| | | | 
   \ V  V /  __/ (__| | | | (_| | |_| |_| | 
    \_/\_/ \___|\___|_| |_|\__,_|\__|\__, | 
                                     |___/  
____________________________________________________
            https://www.chatie.io
  _____      _ _     _  
 | ____|_  _(_) |_  / | 
 |  _| \ \/ / | __| | | 
 | |___ >  <| | |_  | | 
 |_____/_/\_\_|\__| |_| 
@huan

This comment has been minimized.

Copy link
Member Author

huan commented Mar 16, 2018

@SuperAL Could you please try the latest version(0.13.82 or above) of Docker Image again? Because the latest version added some diagnostic output message for this issue.

You can run docker pull zixia/wechaty to get the latest docker image.

@SuperAL

This comment has been minimized.

Copy link

SuperAL commented Mar 16, 2018

@zixia

[root@centos-wechaty alex]# ls
wechaty
[root@centos-wechaty alex]# cd wechaty
[root@centos-wechaty wechaty]# docker run -ti --volume="$(pwd)":/bot --rm zixia/wechaty mybot.js

 __        __        _           _
 \ \      / /__  ___| |__   __ _| |_ _   _
  \ \ /\ / / _ \/ __| '_ \ / _` | __| | | |
   \ V  V /  __/ (__| | | | (_| | |_| |_| |
    \_/\_/ \___|\___|_| |_|\__,_|\__|\__, |
                                     |___/
____________________________________________________
......
Starting Wechaty v0.13.82 with Node.js v9.8.0 ...
Container ERROR: can not found bot file: mybot.js
Container PWD: /wechaty
Container LS: total 436
-rw-r--r--. 1 root root    113 Mar 16 03:28 AUTHORS
-rw-r--r--. 1 root root  50363 Mar 16 03:28 CHANGELOG.md
-rw-r--r--. 1 root root    490 Mar 16 03:28 CODEOWNERS
-rw-r--r--. 1 root root   3210 Mar 16 03:28 CODE_OF_CONDUCT.md
-rw-r--r--. 1 root root   1150 Mar 16 03:28 CONTRIBUTING.md
-rw-r--r--. 1 root root   3820 Mar 16 03:28 Dockerfile
-rw-r--r--. 1 root root   2679 Mar 16 03:28 Dockerfile.alpine
-rw-r--r--. 1 root root    299 Mar 16 03:28 Dockerfile.onbuild
-rw-r--r--. 1 root root  11360 Mar 16 03:28 LICENSE
-rw-r--r--. 1 root root  12180 Mar 16 03:28 README.md
-rw-r--r--. 1 root root     67 Mar 16 03:28 TODO.md
-rw-r--r--. 1 root root    611 Mar 16 03:28 app.json
-rw-r--r--. 1 root root    855 Mar 16 03:28 appveyor.yml
drwxr-xr-x. 2 root root     82 Mar 16 03:28 bin
drwxr-xr-x. 1 root root     17 Mar 16 03:36 dist
drwxr-xr-x. 3 root root     55 Mar 16 03:28 docs
drwxr-xr-x. 6 root root   4096 Mar 16 03:28 examples
-rw-r--r--. 1 root root    803 Mar 16 03:28 index.ts
drwxr-xr-x. 1 root root      6 Mar 16 03:36 node_modules
-rw-r--r--. 1 root root 298175 Mar 16 03:33 package-lock.json
-rw-r--r--. 1 root root   6108 Mar 16 03:28 package.json
drwxr-xr-x. 2 root root    242 Mar 16 03:28 scripts
drwxr-xr-x. 3 root root   4096 Mar 16 03:28 src
drwxr-xr-x. 4 root root    211 Mar 16 03:28 tests
-rw-r--r--. 1 root root    749 Mar 16 03:28 tsconfig.json
-rw-r--r--. 1 root root   2541 Mar 16 03:28 tslint.json
......
  _____      _ _     _
 | ____|_  _(_) |_  / |
 |  _| \ \/ / | __| | |
 | |___ >  <| | |_  | |
 |_____/_/\_\_|\__| |_|

[root@centos-wechaty wechaty]# ll
total 12
-rw-r--r--. 1 alex alex 326 Mar 14 03:53 mybot.js
-rw-rw-r--. 1 alex alex 444 Mar 14 03:07 package.json
-rw-rw-r--. 1 alex alex  13 Mar 14 03:07 README.md

huan added a commit that referenced this issue Mar 16, 2018

@huan

This comment has been minimized.

Copy link
Member Author

huan commented Mar 16, 2018

@SuperAL Could you pull the image again by running docker pull zixia/wechaty(and make sure the version is v0.13.85 or above) and try again?

@SuperAL

This comment has been minimized.

Copy link

SuperAL commented Mar 16, 2018

[alex@centos-wechaty wechaty]$ ll
total 12
-rw-r--r--. 1 alex alex 326 Mar 14 03:53 mybot.js
-rw-rw-r--. 1 alex alex 444 Mar 14 03:07 package.json
-rw-rw-r--. 1 alex alex  13 Mar 14 03:07 README.md
[alex@centos-wechaty wechaty]$ docker run -t -i --rm --volume="$(pwd)":/bot --name=wechaty zixia/wechaty mybot.js

 __        __        _           _          
 \ \      / /__  ___| |__   __ _| |_ _   _  
  \ \ /\ / / _ \/ __| '_ \ / _` | __| | | | 
   \ V  V /  __/ (__| | | | (_| | |_| |_| | 
    \_/\_/ \___|\___|_| |_|\__,_|\__|\__, | 
                                     |___/  
____________________________________________________            https://www.chatie.io
  ____                            _   _              / ___|___  _ __  _ __   ___  ___| |_(_)_ __   __ _ | |   / _ \| '_ \| '_ \ / _ \/ __| __| | '_ \ / _` || |__| (_) | | | | | | |  __/ (__| |_| | | | | (_| | \____\___/|_| |_|_| |_|\___|\___|\__|_|_| |_|\__, |                                              |___/   ____ _           _   ____        _       
 / ___| |__   __ _| |_| __ )  ___ | |_ ___ 
| |   | '_ \ / _` | __|  _ \ / _ \| __/ __|
| |___| | | | (_| | |_| |_) | (_) | |_\__ \
 \____|_| |_|\__,_|\__|____/ \___/ \__|___/
                                           

Starting Wechaty v0.13.82 with Node.js v9.8.0 ...
Container ERROR: can not found bot file: mybot.js
Container PWD: /wechaty
ls: cannot open directory '/bot': Permission denied
Container LS: 
  _____                _     _           _                 _   _              
 |_   _| __ ___  _   _| |__ | | ___  ___| |__   ___   ___ | |_(_)_ __   __ _  
   | || '__/ _ \| | | | '_ \| |/ _ \/ __| '_ \ / _ \ / _ \| __| | '_ \ / _` | 
   | || | | (_) | |_| | |_) | |  __/\__ \ | | | (_) | (_) | |_| | | | | (_| | 
   |_||_|  \___/ \__,_|_.__/|_|\___||___/_| |_|\___/ \___/ \__|_|_| |_|\__, | 
                                                                       |___/  

    Troubleshooting:

    1. Did you bind the current directory into container?

      check your `docker run ...` command, if there's no `volumn` arg,
      then you need to add it so that we can bind the volume of /bot:

        `--volume="$(pwd)":/bot`

      this will let the container visit your current directory.

    2. Are you sure your .js/.ts files aren't .js.txt/.ts.txt?

      this could be a problem on new Windows installs (file
      extensions hidden by default).

    if you still have issue, please have a look at
      https://github.com/chatie/wechaty/issues/66
      and do a search in issues, that might be help.

 __        __        _           _          
 \ \      / /__  ___| |__   __ _| |_ _   _  
  \ \ /\ / / _ \/ __| '_ \ / _` | __| | | | 
   \ V  V /  __/ (__| | | | (_| | |_| |_| | 
    \_/\_/ \___|\___|_| |_|\__,_|\__|\__, | 
                                     |___/  
____________________________________________________            https://www.chatie.io
  _____      _ _     _  
 | ____|_  _(_) |_  / | 
 |  _| \ \/ / | __| | | 
 | |___ >  <| | |_  | | 
 |_____/_/\_\_|\__| |_| 
                        
[alex@centos-wechaty wechaty]$ 
@huan

This comment has been minimized.

Copy link
Member Author

huan commented Mar 16, 2018

According to your log messages:

Starting Wechaty v0.13.82 with Node.js v9.8.0 ...
Container ERROR: can not found bot file: mybot.js
Container PWD: /wechaty
ls: cannot open directory '/bot': Permission denied
Container LS: 

ls: cannot open directory '/bot': Permission denied

It seems something was wrong with your current directory.

Can you try to create a new directory to test again?

For example, something like the following commands:

$ mkdir /tmp/wechaty-test
$ cd /tmp/wechaty-test
$ cp /home/alex/wechat-bot/mybot.js .
$ docker run -t -i --rm --volume="$(pwd)":/bot --name=wechaty zixia/wechaty mybot.js
@SuperAL

This comment has been minimized.

Copy link

SuperAL commented Mar 17, 2018

It’s working. Thankfully!

@huan

This comment has been minimized.

Copy link
Member Author

huan commented Mar 17, 2018

@SuperAL Glad to hear that!

However, I feel it's wired.

Could you please tell me how did you fix this issue, and what's the problem that caused the can not found bot file: mybot.js/Permission denied error before? Because it seems not only you are facing this problem, you could help others by sharing your experiences.

@SuperAL

This comment has been minimized.

Copy link

SuperAL commented Mar 17, 2018

I followed your advice. Here is how I solved the problem:

mkdir /tmp/wechaty-test
cd /tmp/wechaty-test
cp /home/alex/wechaty/mybot.js .
docker run -t -i --rm --volume="$(pwd)":/bot --name=wechaty zixia/wechaty mybot.js

And it worked.

Let me illustrate how I encountered the problem at first:

  1. I buy a VPS on DigitalOcean
  2. I created a non-root user on the server and install git
  3. I git clone the repository ‘wechaty-getting-started’
  4. cd wechaty-getting-started
  5. docker run -t -i --rm --volume="$(pwd)":/bot --name=wechaty zixia/wechaty mybot.js
  6. And then it shows error: can not found bot file: mybot.js
@huan

This comment has been minimized.

Copy link
Member Author

huan commented Mar 17, 2018

Would you mind opening your VPS to let me have a look at it?

If so, my ssh public key is:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCYtMjm5fEkWHGRkpjoP2S89IjmrojaZev8FYFO/SpQCNjPA0AsdEbjLUdX7huPDB7n9Fd/XsRHyBFDZ7byyq8WnDBGrt9rg7vTH6g+jX7Y3eLhXId6fKbgMs5fkG3/SEC/uK+xzPuGyD8CiS3nNiqX5egyx4Tfdx0TrG2z15ZtD874wOKbSi59tHJCmYpIph4GDJo5olTuZaAozlzuZ60N6KLbsDOacxbrmoQ4Fyn+erHENAxKgi0AbpRgwpT62f9ew7EIJNAfran82aq9iCgp+nUn6BRMRRKIE0fC3F1j3UfqZsFqBaQssgwmXvhKz90ShV122FeqiIJQAhDeXQnZ
@huan

This comment has been minimized.

Copy link
Member Author

huan commented Mar 19, 2018

@SuperAL Thanks for your VPS.

I had logged in and re-produced your issue as the following output messages:

[alex@centos-wechaty wechaty]$ cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core) 

[alex@centos-wechaty wechaty]$ id
uid=1001(alex) gid=1001(alex) groups=1001(alex),10(wheel),994(dockerroot),1002(docker) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

[alex@centos-wechaty wechaty]$ pwd
/home/alex/wechaty

[alex@centos-wechaty wechaty]$ ls -ld /home
drwxr-xr-x. 4 root root 32 Mar 19 01:04 /home

[alex@centos-wechaty wechaty]$ ls -ld /home/alex/
drwxr-xr-x. 5 alex alex 153 Mar 19 01:10 /home/alex/

[alex@centos-wechaty wechaty]$ ls -ld /home/alex/wechaty/
drwxr-xr-x. 3 alex alex 71 Mar 14 03:53 /home/alex/wechaty/

[alex@centos-wechaty wechaty]$ docker run -t -i --rm --volume="$(pwd)":/bot --name=wechaty zixia/wechaty mybot.js
Starting Wechaty v0.13.82 with Node.js v9.8.0 ...
Container ERROR: can not found bot file: mybot.js
Container PWD: /wechaty
ls: cannot open directory '/bot': Permission denied
Container LS: 

[alex@centos-wechaty wechaty]$ sudo su -

[root@centos-wechaty wechaty]# id
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

[root@centos-wechaty wechaty]# sudo docker run -t -i --rm --volume="$(pwd)":/bot --name=wechaty zixia/wechaty mybot.js
Starting Wechaty v0.13.82 with Node.js v9.8.0 ...
Container ERROR: can not found bot file: mybot.js
Container PWD: /wechaty
ls: cannot open directory '/bot': Permission denied
Container LS: 

[root@centos-wechaty wechaty]# 

The reason you are experiencing this is that SELinux is enabled by default with your CentOS installation. (Ubuntu default installation had never seen this.)

For your case: the root user has no permission to read your directory, what you need to do is to run:

setenforce 0

setenforce 0 will disable SELinux for you.

See Also

  1. Find if permission denied errors are caused by SELinux

I believe this problem/solution should be added to our FAQ in order to help the future users who are using CentOS with SELinux enabled.

@SuperAL

This comment has been minimized.

Copy link

SuperAL commented Mar 19, 2018

@zixia Thank you so much for your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment