Running Discourse on Docker for Mac

Hi guys (@sam & @JaredReisinger)! I’m trying to get dev workflow with docker.

I built discourse_dev image:

cd discourse_docker
cp templates/redis.template.yml image/discourse_dev/
cp templates/postgres.template.yml image/discourse_dev/
cd image/discourse_dev/
docker build -t discourse_dev .

run bootstrap:

cd discourse
./bin/docker/boot_dev -i

and stuck with Postgresql access rights:

Couldn't create database for {"prepared_statements"=>false, "adapter"=>"postgresql", "database"=>"discourse_development", "min_messages"=>"warning", "pool"=>5, "timeout"=>5000, "host_names"=>["localhost"]}

So I suspect that I’m doing something wrong from the beginning.

Any simple quick setup steps that we can convert later to DEVELOPMENT-OSX-DOCKER.md ?

1 Like

I am trying to use this approach, but when running ./bin/docker/boot_dev --init I get the error

Unable to find image 'discourse/discourse_dev:latest' locally
Pulling repository docker.io/discourse/discourse_dev
docker: Error: image discourse/discourse_dev:latest not found.

Any help?
Thanks

I’ll push a new dev image today, cooking it right now.

5 Likes

I’m getting the same error message with docker for windows (both the main and the toolbox version of docker for windows). Perhaps the issue is with non Linux docker engines?

Try this:
http://stackoverflow.com/a/41381813/2639425

It works fine for me,fowllowing is my configuration:

⋊> grep -A 6 '^volumes:' /var/discourse/containers/app.yml
volumes:
  - volume:
      host: /Applications/DockerShareFolder/discourse/shared/standalone
      guest: /shared
  - volume:
      host: /Applications/DockerShareFolder/discourse/shared/standalone/log/var-log
      guest: /var/log
2 Likes

Following:

Doing dev work in docker on a mac may be workable!

Rails Boot Slowdown
Host 5.64
Virtual Box 6.15 9%
Virtual Box + Docker 8.78 55%
Docker Mac (cached) 11.2 98%
Docker Mac (uncached) 15.7 178%

Note: for Docker setup on virtual box has gems are in AUFS and working directory in a mounted volume. On mac the working directory is a cache mounted volume. It is likely performance would improve if overlay was used or gems are mounted on the host to avoid virtualized file system.

Docker for Mac … uncached:

sams-MBP:discourse sam$ time d/rails r 'puts'


real	0m19.035s
user	0m0.016s
sys	0m0.014s
sams-MBP:discourse sam$ time d/rails r 'puts'


real	0m15.702s
user	0m0.017s
sys	0m0.014s
sams-MBP:discourse sam$ time d/rails r 'puts'


real	0m17.290s
user	0m0.016s
sys	0m0.011s

Docker for mac … cached

sams-MBP:discourse sam$ time d/rails r 'puts'


real	0m11.430s
user	0m0.018s
sys	0m0.012s
sams-MBP:discourse sam$ time d/rails r 'puts'


real	0m11.293s
user	0m0.019s
sys	0m0.012s
sams-MBP:discourse sam$ time d/rails r 'puts'


real	0m11.995s
user	0m0.017s
sys	0m0.012s

Ruby installed on host

sams-MBP:discourse sam$ time bin/rails r 'puts'


real	0m7.204s
user	0m4.541s
sys	0m1.780s
sams-MBP:discourse sam$ time bin/rails r 'puts'


real	0m5.644s
user	0m4.319s
sys	0m1.254s
sams-MBP:discourse sam$ time bin/rails r 'puts'


real	0m5.646s
user	0m4.329s
sys	0m1.256s

VirtualBox + docker on the same host

sam@ubuntu:~/Source/discourse$ time d/rails r 'puts'


real	0m12.519s
user	0m0.016s
sys	0m0.012s
sam@ubuntu:~/Source/discourse$ time d/rails r 'puts'


real	0m8.786s
user	0m0.016s
sys	0m0.000s
sam@ubuntu:~/Source/discourse$ time d/rails r 'puts'


real	0m8.733s
user	0m0.008s
sys	0m0.004s

VirtualBox, no docker

real	0m9.386s
user	0m5.332s
sys	0m1.692s
sam@ubuntu:~/Source/discourse$ time bin/rails r 'puts'


real	0m6.032s
user	0m4.796s
sys	0m1.116s
sam@ubuntu:~/Source/discourse$ time bin/rails r 'puts'


real	0m6.155s
user	0m4.924s
sys	0m1.104s
sam@ubuntu:~/Source/discourse$ time bin/rails r 'puts'


real	0m6.112s
user	0m4.804s
sys	0m1.180s

8 Likes

This is looking like the most promising solution for Mac/windows dev

Going to test it out

http://docker-sync.io

2 Likes

Did docker-sync improve performance @sam? (or anyone else?) :slight_smile:

docker sync should improve perf significantly, I have not measured it cause I use Linux.

4 Likes

I’m struggling to understand how to set up docker-sync to develop on a mac.

I’ve followed the setup guide at discourse/bin/docker at master · discourse/discourse · GitHub to set up docker - which works fine, just veeery slowly.

A couple of questions:

  1. To setup docker-sync, I have to create at least one docker-sync.yml file

    In this file I have to select which directories should sync - but I’m not sure which?

  2. To start docker-sync, I run docker-sync start, but do I run that as well as ./bin/docker/rails s?

Appreciate tips if anyone out there has this set up already :slight_smile:

docker-sync user here :raised_hand:

Essentially, I created a modified version of bin/docker/boot_dev to start the container in detached mode with the docker-sync'ed volumes, so the rest of the Discourse bin/docker scripts would still work.


This is how I structured everything.

.
|-- src/
|-- docker-sync.yml
|-- up
|-- down

src/ is the cloned Discourse git repo.

up is the aforementioned modified boot_dev script, to docker-sync start and start the docker container; down stops docker-sync and the docker container.

My `docker-sync.yml`
version: "2"

options:
  verbose: true
syncs:
  discourse-sync:
    src: './src'
    sync_userid: '1000'
    sync_groupid: '1000'
    sync_excludes: ['tmp/cache', '.DS_Store', '._*', 'data/postgres*', 'log/development.log']
  postgres-sync:
    src: './src/data/postgres'
    sync_userid: '107'
    sync_groupid: '112'

Critical snippet in `up`
docker-sync start

docker run -d -p 1080:1080 -p 3000:3000 \
 --volumes-from discourse-sync \
 --volumes-from postgres-sync \
 -v "postgres-sync:/shared/postgres_data:nocopy" \
 -v "discourse-sync:/src:nocopy" \
 -e BUNDLE_PATH=/src/vendor/bundle \
 --hostname=discourse \
 --name=discourse_dev \
 --restart=always \
 discourse/discourse_dev:release /sbin/boot

I kinda forgot why I have two separate sync’ed volumes: one for the database and another for the source code.

Never got around to perfect the script since it just works :sweat_smile: Lemme know if you’ve any questions!

6 Likes

Thanks! @xrav3nz! That was very helpful :slight_smile:

I think I’m very close to getting it to work.

Here’s what I did:

  1. Used your docker-sync.yml, put it in the directory containing my app directory.
  2. Duplicated the boot_dev script and replaced the docker run -d... line with the content in your second snippet. Saved it as up in the same directory as the docker-sync file.
  3. My app directory is named discourse, so I replaced src with discourse in both of the snippets.
  4. Ran ./up in the directory containing the up file.
  5. Docker-sync and Docker start

How do I start rails? I tested running ./up --init which fails with this error:

Installing gems...
./up: line 47: /Users/jt/app/bundle: No such file or directory

On that line it attempts to run "${SCRIPTPATH}/bundle" install so it is not registering as a regular “bundle install”

If I run ./bin/docker/rails s it now fails too saying that I’m not doing the command correctly:

Usage:
  rails new APP_PATH [options]

I’m sure I’m just missing a small puzzle piece here :smiley: Thanks again :slight_smile:

Since up is not in the bin/docker directory with the rest of the scripts, $SCRIPT_PATH is incorrect and thus $SCRIPT_PATH/bundle does not exist.

The easiest fix would be to only start docker-sync and the docker containers in up, and run the rest of the scripts separately.

For example,

$ ./up

# this is the initialization process in `boot_dev --init`
$ discourse/d/bundle install
$ discourse/d/rake db:migrate
$ discourse/d/rake admin:create

$ discourse/d/rails s

I hope it works this time, let me know how it goes.

4 Likes

Thanks! :slight_smile:

Running discourse/d/bundle install in the directory containing discourse says:
Could not locate Gemfile

Running discourse/d/rails s gives the same error as in my previous post.

discourse/d/bundle install --gemfile=/discourse/Gemfile seems to work…

Hmmm :thinking: interesting…

In up:

docker run -d -p 1080:1080 -p 3000:3000 \
 --volumes-from discourse-sync \
 --volumes-from postgres-sync \
 -v "postgres-sync:/shared/postgres_data:nocopy" \
 -v "discourse-sync:/src:nocopy" \
 -e BUNDLE_PATH=/src/vendor/bundle \
 --hostname=discourse \
 --name=discourse_dev \
 --restart=always \
 discourse/discourse_dev:release /sbin/boot

Did you replace the src in -v "discourse-sync:/src:nocopy" to discourse as well? This src refers to the directory in the container. Sorry if my folder names are a bit confusing…

Yes, I did :slight_smile: Is there anything else that has been changed in the up file?

I was trying to say that -v "discourse-sync:/src:nocopy" should not be changed, otherwise the source code would be mounted to a different directory in the container. This explains why neither rails nor bundler could find the source code. :man_facepalming:

2 Likes

D’oh :wink: Brilliant, thank you! Having this up and running makes dev work so much easier! :slight_smile:

I owe you a :beer:

1 Like

Be sure to do a PR to discourse making this config optional so we both document and make switches for it.

6 Likes