Skip to content

Dockerize Wechaty for easy start #66

@huan

Description

@huan

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: Linux: ./electron: error while loading shared libraries: libgconf-2.so.4 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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions