Skip to main content

Deploy with Docker

Powered by Wechaty Docker Pulls Docker Stars Build Status

Docker allows you to create virtualized sandboxes to run and deploy software. Use Docker to explore ready-to-go containers without worrying about dependencies. Setting up Docker is easier than ever by just pushing a button to start running the Docker one-click app.


  • Your OS must be Docker compatible, click here to see supported OS versions.
  • If you have installed any older versions of Docker, including docker,, or docker-engine, uninstall it.
 sudo apt-get remove docker docker-engine containerd runc


The quick and easy way to install Docker is to get the script from and runs it to install the latest stable release of Docker on your system.

Docker installation docs

Getting Started after Deployment

To get familiar with the Docker Environment, you can try Running hello-world under 3 minutes with Docker.

  1. Run the below command to pull Wechaty in docker:
docker pull wechaty/wechaty

The best practice of using Wechaty Docker is as follows:

$ cat > mybot.ts <<'EOF'
import { Wechaty } from '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() {
docker run \
-t -i --rm \
--privileged \
--network=host \
--mount type=bind,source="$(pwd)",target=/bot \
wechaty/wechaty:latest \

$ wechaty mybot.ts

Know the commands used above

  • -t : Allocate a pseudo-TTY
  • -i : Keep STDIN open even if not attached
  • --rm : Automatically remove the container when it exits
  • --privileged : Give extended privileges to this container
  • --network=host : use the Docker host network stack
  • -e WECHATY_LOG="$WECHATY_LOG" : Pass the environment variable WECHATY_LOG into the container
  • --volume="$(pwd)":/bot : Bind current directory("$(pwd)") to '/bot' inside the container, by mounting the volume
  • --name=wechaty : Assign wechaty as the container name
  • wechaty/wechaty:latest : Image name on docker hub, here's our wechaty/wechaty with latest version
  • mybot.js : File contains code wrote by you, should be placed in current directory ./

See Also: Dockerize Wechaty for easy start #66


Get started with various Examples written in JavaScript. Run example ChatBot is as easy as run hello world example above, as long as you are using Docker:

cd example
wechaty ding-dong-bot.js

Run Wechaty as a Hostie

Running your wechaty as a hostie requires WECHATY_TOKEN so as to manage wechaty on the chatbot cloud manager:

export WECHATY_TOKEN="your token here"
docker run -e WECHATY_TOKEN="$WECHATY_TOKEN" wechaty/wechaty



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

FROM 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 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 build -t wechaty

Next Steps

Now that you’ve learned how to install docker and work with your Wechaty Docker. See the following guides to begin:

  1. Wechaty Getting Started:
  2. Heroku Wechaty Getting Started:
  3. Docker Wechaty GitHub repo: