Huan LI edited this page Aug 13, 2018 · 47 revisions

Docker Pulls Docker Stars Docker Layers

Wechaty is fully dockerized. So it will be very easy to be used as a MicroService.

Getting Started with Docker

Getting Started Template for Docker Users:

Install Docker

Quick & easy install Docker via:

curl -sSL | sh


wget -qO- | sh

Get to know more about Docker at:


The best practice of using Wechaty Docker is like the following:

$ cat > mybot.js <<'EOF'
const { Wechaty } = require('wechaty')

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

$ function wechaty() {
  sudo docker run \
    -t -i --rm \
    --mount type=bind,source="$(pwd)",target=/bot \
    zixia/wechaty:latest \

$ wechaty mybot.js

see? death easy to use!

You might want to confirm that you can download zixia/wechaty image successfully by run sudo docker pull zixia/wechaty, and this command is also able to help you upgrade the image to the latest version.

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("$(pwd)") to '/bot' inside the container, by mounting the volume
  6. --name=wechaty : Assign wechaty as the container name
  7. zixia/wechaty:latest : Image name on docker hub, here's our zixia/wechaty with latest version
  8. mybot.js : File contains code wrote by you, should be placed in current directory ./

Run Examples

There's many Wechaty ChatBot Examples in the example directory, and all of them are writen in TypeScript.

Run example ChatBot is as easy as run hello world example above, as long as you are using Docker:

$ cd example

$ wechaty media-file-bot.ts


Run Wechaty as a Chatie

export WECHATY_TOKEN="your token here"

docker run -e WECHATY_TOKEN="$WECHATY_TOKEN" zixia/wechaty

WECHATY_TOKEN is required here, because you need this key to managing wechaty on the chatbot cloud manager:


Put this line(and only this line) to your Dockerfile:

FROM zixia/wechaty:onbuild

This image makes building derivative images easier. For most use cases, creating a Dockerfile in the base of your project directory with the line FROM zixia/wechaty:onbuild will be enough to create a stand-alone image for your project.

  1. The onbuild variant is really useful for "getting off the ground running" (zero to Dockerized in a short period of time)
  2. This onbuild variant will only install npm packages according to the package.json
  3. The npm installs devDependencies by default, which is undesirable if you're building a production image. To avoid this pass NODE_ENV as a build argument i.e. docker build --build-arg NODE_ENV=production ….

Docker Intro

How to Install Docker

Use Docker in China

There could be some issue like connection timeout or very slow when docker pull in China due to Internet Censorship by GFW.

If you have this kind of issue, you can use either DaoCloud accelerator or AliYun accelerator.

$ docker pull

You can add "" to the registry-mirrors array in /etc/docker/daemon.json to pull from the China registry mirror by default.

  "registry-mirrors": [""]

Save the file and reload Docker for the change to take effect.

Learn more from:


docker build -t wechaty .
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.