# (Solved) Websocket connection fails with 'Mattermost on Docker for production use'

**URL:** <https://forum.mattermost.com/t/solved-websocket-connection-fails-with-mattermost-on-docker-for-production-use/17645>\
**Category:** Troubleshooting\
**Created:** [January 3, 2024, 3:48pm UTC](https://forum.mattermost.com/t/solved-websocket-connection-fails-with-mattermost-on-docker-for-production-use/17645 "2024-01-03T15:48:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wes](https://avatars.discourse-cdn.com/v4/letter/w/e9c0ed/32.png) [@wes](https://forum.mattermost.com/u/wes)\
**Post date:** [January 3, 2024, 3:48pm UTC](https://forum.mattermost.com/t/solved-websocket-connection-fails-with-mattermost-on-docker-for-production-use/17645/1 "2024-01-03T15:48:45Z")

</div>

I referred to [Install Mattermost via Docker — Mattermost documentation](https://docs.mattermost.com/install/install-docker.html#deploy-mattermost-on-docker-for-production-use) to deploy Mattermost locally on Ubuntu (with WSL).

The installation worked fine and I can start Mattermost (without nginx) using

```auto
sudo docker compose -f docker-compose.yml -f docker-compose.without-nginx.yml up -d

```

I created a new user

```auto
$ docker exec -ti 478076cfedfe mmctl --local user create --email localbot@ ****--username localbot --password***
Created user localbot

```

I created a personal access token ([Personal Access Tokens — Mattermost documentation](https://docs.mattermost.com/developer/personal-access-tokens.html)) for this user and using that I can make API calls -

```auto
$ curl -i -H 'Authorization: Bearer ebg***' http://localhost:8065/api/v4/users/me
HTTP/1.1 200 OK
Content-Type: application/json
Etag: 7.8.14.apy1htzdgibxzeeu1o5u9ysese.1704231806528..0.true.true.0
Expires: 0
Permissions-Policy:
Referrer-Policy: no-referrer
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-Request-Id: wsnd5sxoa38ntfd9i8m9frszjr
X-Version-Id: 7.8.14.7.8.14.565e53075911beb8df97f2b871fd3108.false
Date: Tue, 02 Jan 2024 22:51:18 GMT
Content-Length: 747

{"id":"apy1htzdgibxzeeu1o5u9ysese","create_at":1704231568613,"update_at":1704231806528,"delete_at":0,"username":"localbot","auth_data":"","auth_service":"","email":"localbot@***","nickname":"","first_name":"","last_name":"","position":"","roles":"system_user system_user_access_token system_post_all","notify_props":{"channel":"true","comments":"never","desktop":"mention","desktop_sound":"true","desktop_threads":"all","email":"true","email_threads":"all","first_name":"false","mention_keys":"","push":"mention","push_status":"away","push_threads":"all"},"last_password_update":1704231568613,"locale":"en","timezone":{"automaticTimezone":"America/New_York","manualTimezone":"","useAutomaticTimezone":"true"},"disable_welcome_email":false}

```

Now I want to connect to the Websocket ([Mattermost API Reference](https://api.mattermost.com/#tag/WebSocket)) and authenticate with this same personal access token. The doc says

> To authenticate with an authentication challenge, first connect the WebSocket and **then** send the following JSON over the connection…

This suggests that the initial connection should just work without issues and then an authentication message needs to be sent. However, this initial connection fails. I tried the following code -

```auto
<html>
   <head><title>Welcome to Websocket Test</title>

<body>

<script>
  let websocketUrl = "ws://localhost:8065/api/v4/websocket";
  const ws = new WebSocket(websocketUrl);
  ws.onopen = () => {
     console.log('Websocket opened! Subscribing...');
  }

ws.onmessage = (event) => {
  const message = JSON.parse(event.data);
  console.log("Got message", message);
};

</script>

</body>

</html>

```

And I always get

```auto
WebSocket connection to 'ws://localhost:8065/api/v4/websocket' failed: 

```

What am I missing?

I have hardly changed any of the configuration and I am simply using the default. The only thing I changed was setting EnableLocalMode to true in config.json, so that I could create users from the command line.

---

<div class="post-metadata">

**Author:** ![john.oliver](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/john.oliver/32/6436_2.png) [@john.oliver](https://forum.mattermost.com/u/john.oliver)\
**Post date:** [January 3, 2024, 4:27pm UTC](https://forum.mattermost.com/t/solved-websocket-connection-fails-with-mattermost-on-docker-for-production-use/17645/2 "2024-01-03T16:27:07Z")

</div>

The first thing I always think of with WebSocket issues is [Integrations configuration settings — Mattermost documentation](https://docs.mattermost.com/configure/integrations-configuration-settings.html#integrate-allowcorsfrom)

---

<div class="post-metadata">

**Author:** ![wes](https://avatars.discourse-cdn.com/v4/letter/w/e9c0ed/32.png) [@wes](https://forum.mattermost.com/u/wes)\
**Post date:** [January 3, 2024, 4:59pm UTC](https://forum.mattermost.com/t/solved-websocket-connection-fails-with-mattermost-on-docker-for-production-use/17645/3 "2024-01-03T16:59:04Z")

</div>

@john.oliver thank you for the quick response! Setting the  
“Enable cross-origin requests from:” to \* fixed the problem.
