Install Discourse for development using Docker

That should be d/rake admin:create I suspect …

Sadly no :frowning:
OCI runtime exec failed: exec failed: unable to start container process: exec: "bin/rake": stat bin/rake: no such file or directory: unknown

what was the result of: d/boot_dev --init ?

Using source in: /home/martyn/discourse
Using data in:   /home/martyn/discourse/data/postgres
release: Pulling from discourse/discourse_dev
Digest: sha256:b64199f510bd9831af81ba8268bef3beff2abb45d0a264a0e29b35cfc3986f05
Status: Image is up to date for discourse/discourse_dev:release
docker.io/discourse/discourse_dev:release
docker: Error response from daemon: Conflict. The container name "/discourse_dev" is already in use by container "44c83548a9a9060716aa7d4fd803e239227f48375625f1d27da19b3d4162c56a". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.

OK so you have built the container.

That’s very strange. I have just installed in WSL from scratch and it worked for me, though I needed to run d/exec yarn manually.

I suggest stopping, deleting your container and starting again and watch out for errors announced in the console.

1 Like

I’ve been working on getting a Discourse dev environment going with the Docker instructions, and I’m seeing errors when running any of the Yarn commands. The Ruby commands work fine, but running d/yarn (and any of its subcommands) fail with this error:

discourse(v3.1.3) $ d/exec yarn -v

<--- Last few GCs --->


<--- JS stacktrace --->


#
# Fatal javascript OOM in MemoryChunk allocation failed during deserialization.
#

I’m on Fedora 39 with Docker 24.0.7. I haven’t modified anything other than checking out Discourse from Git and changing to the v3.1.3 tag.

Has anyone seen this error before? Thanks!

Sounds like it’s running out of memory:

How much RAM does it have?

My machine has 64 GB of RAM, and I don’t believe I’ve set any limits on Docker’s memory usage. I’ve just got a standard Docker install running.


Edit: it’s interesting, Node commands work but Yarn fails:

discourse(v3.1.3*) $ d/exec node -v
v18.17.1
discourse(v3.1.3*) $ d/exec yarn -v

<--- Last few GCs --->


<--- JS stacktrace --->


#
# Fatal javascript OOM in MemoryChunk allocation failed during deserialization.
#

A quick update: Node commands fail as well upon further testing:

discourse(v3.1.3*) $ d/exec node --help

<--- Last few GCs --->


<--- JS stacktrace --->


#
# Fatal javascript OOM in MemoryChunk allocation failed during deserialization.
#

Anything other than d/exec node -v throws that error. :thinking: Will continue to investigate and try to see if I can figure out a solution.

I figured out a fix for my problem. It’s a bit of a convoluted, hacky process, but it works. In summary, upgrading to Node.js 20.x.x fixed my issue.

I created a Docker image that uses Node.js v20.x.x instead of the default v18.x.x that the Discourse dev Docker image uses.

I started by creating this Dockerfile:

# NAME: discourse_node20
FROM discourse/discourse_dev:release

# upgrade node to LTS 20.x.x
ENV NODE_MAJOR=20
RUN apt-get update
RUN apt-get install -y ca-certificates curl gnupg
RUN mkdir -p /etc/apt/keyrings
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN apt-get update
RUN apt-get install nodejs -y

Then I built the image: docker build -t discourse_node20 - < Dockerfile

Then I updated d/boot_dev’s docker run command to use the discourse_node20 image and not pull discourse/discourse_dev:release since it isn’t being used. Here’s that updated command in d/boot_dev:

# comment the line below out 
# docker pull discourse/discourse_dev:release
docker run \
    -d \
    -p $local_publish:8025:8025 \
    -p $local_publish:3000:3000 \
    -p $local_publish:4200:4200 \
    -p $local_publish:9292:9292 \
    -p $local_publish:9405:9405 \
    -v "$DATA_DIR:/shared/postgres_data:delegated" \
    -v "$SOURCE_DIR:/src:delegated" \
    -e UNICORN_BIND_ALL=true \
    -e NODE_OPTIONS=--max_old_space_size=8192 \
    $mount_plugin_symlinks \
    $ENV_ARGS \
    --hostname=discourse \
    --name=discourse_dev \
    --restart=always \
    discourse_node20 /sbin/boot

From there I was able to successfully d/boot_dev --init, d/rails s, and d/ember-cli giving me a functioning dev environment in Docker 24 and Fedora 39.


I don’t know why Node 20.x.x fixes the issue. Hopefully this is fixed upstream in the main dev image. I’d be happy to contribute a pull request but upgrading a major dependency seems like something beyond just a drive-by PR by me. :smile_cat: Well, at least I’m unblocked for now!

Anyone got this working on a Raspberry Pi? (yes I know the production config is supported). What changes/config is needed?

I get:

WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested

And then the container just crashes and restarts constantly.

UPDATE: Ah, I see that a supporting image has not yet been introduced? Compare:

https://hub.docker.com/r/discourse/base/tags

(which is supported)

with

https://hub.docker.com/r/discourse/discourse_dev/tags

There’s no arm64 version listed for latter …

Anybody on Mac OS (13.6.3) (Intel) successful in getting Discourse in docker to run…and can share how they got past the Error: Cannot find module 'esbuild' error?

I noticed in the boot_dev application that yarn is never run for the top-level directory, only app/assets/javascripts/discourse:

echo "Yarn install..."
"${SCRIPTPATH}/exec" yarn install --cwd app/assets/javascripts/discourse

Therefore it makes sense that esbuild isn’t installed, since that is a dependency described in the top-level package.json.

However, this package.json cannot be installed outside the container, as the wrong version of esbuild will be installed (Mac, not Linux…but the container needs Linux).

Shouldn’t there be a line in boot_dev just above “installing gems” that looks like this?

echo "Installing top-level package.json ..."
"${SCRIPTPATH}/exec" yarn install

When I add a line like that, I can get past the migrations step without an esbuild error…

Has this been fixed? I got an install up an running, but the next day when I came back to it and ran d/boot_dev it gave me this warning and will not create my container anymore.

Discourse development is unlikely to work using Docker's architecture emulation.
Please try a native development installation.
Using source in: /Users/n_selvidge/discourse
Using data in:   /Users/n_selvidge/discourse/data/postgres

How to install discourse development via http_proxy?

Get in touch with the proxy provider and make sure those calls are permitted?

Got the same error when running d/rails s,

/home/discourse/.bundle/gems/ruby/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_adapters/postgresql_adapter.rb:87:in `rescue in new_client': connection to server at "10.169.51.142", port 5432 failed: Connection refused (ActiveRecord::ConnectionNotEstablished)
	Is the server running on that host and accepting TCP/IP connections?

Any help is appreciated!

d/rails s returns:
Error response from daemon: No such container: discourse_dev

Any suggestions?

1 Like

Did you run d/boot_dev first?

1 Like

Hi, can I get it to bind to 0.0.0.0 instead?

image
image

Yes, I did enter that, thanks. To start over, I assume I delete the container from the Docker GUI as well as the discourse repository folder?