laravel-echo-server icon indicating copy to clipboard operation
laravel-echo-server copied to clipboard

Laravel Echo Serve in docker exited with code 0

Open lokingwei opened this issue 6 years ago • 6 comments

I used laradock setting to create laravel-echo-server container which running in VM. Whenever I shutdown the VM ungracefully (a.k.a force shut down), I unable to start back the server within the same container.

Unfortunately, there's no log or error code for me to indicate what is happening.

The only output I have is:

Starting laradock_laravel-echo-server_1_e1682066e464 ... done
Attaching to laradock_laravel-echo-server_1_e1682066e464
laravel-echo-server_1_e1682066e464 |
laravel-echo-server_1_e1682066e464 | > [email protected] start /usr/src/app
laravel-echo-server_1_e1682066e464 | > laravel-echo-server start "--force"
laravel-echo-server_1_e1682066e464 |
laradock_laravel-echo-server_1_e1682066e464 exited with code 0

My Dockerfile:

FROM node:alpine

# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY package.json /usr/src/app/

RUN npm install

# Bundle app source
COPY laravel-echo-server.json /usr/src/app/laravel-echo-server.json

EXPOSE 3000
CMD [ "npm", "start", "--", "--force"]

My package.json

{
  "name": "laravel-echo-server-docker",
  "description": "Docker container for running laravel-echo-server",
  "version": "0.0.1",
  "license": "MIT",
  "dependencies": {
    "laravel-echo-server": "1.5"
  },
  "scripts": {
    "start": "laravel-echo-server start"
  }
}

My laravel-echo-server.json

{
	"authHost": "php-fpm",
	"authEndpoint": "/broadcasting/auth",
	"clients": [],
	"database": "redis",
	"databaseConfig": {
		"redis": {
			"port": "6379",
			"host": "redis"
		}
	},
	"devMode": true,
	"host": null,
	"port": "6001",
	"protocol": "http",
	"socketio": {},
	"sslCertPath": "",
	"sslKeyPath": ""
}

My docker-compose.yml:

laravel-echo-server:
      build:
        context: ./laravel-echo-server
      volumes:
        - ./laravel-echo-server/laravel-echo-server.json:/app/laravel-echo-server.json
      ports:
        - "${LARAVEL_ECHO_SERVER_PORT}:6001"
      depends_on:
        - redis
      networks:
        - frontend
        - backend

lokingwei avatar May 22 '19 04:05 lokingwei

After investigation with the broken container, here's my finding:

In the broken container (the one didn't get gracefully shut down). If I execute npm start, it throws me this error:

Error: There is already a server running! Use the option '--force' to stop it and start another one.

However, on the second execution of npm start, the server starts successfully.

If I execute npm start -- --force, it throws me:

Terminated

And the same, the second execution of npm start -- --force, the server starts successfully.

lokingwei avatar May 24 '19 04:05 lokingwei

Have had the same issue, rebuilding container with --no-cache flag helps

iolinpic avatar Sep 19 '19 09:09 iolinpic

I fixed the issue by stopping the server, and then starting it again.

secmohammed avatar Dec 09 '19 12:12 secmohammed

there is a laravel-echo-server.lock file created, if you delete that it should work

patricKogler avatar Feb 07 '20 08:02 patricKogler

there is a laravel-echo-server.lock file created, if you delete that it should work

L A R A V E L E C H O S E R V E R

version 1.6.2

⚠ Starting server in DEV mode...

events.js:174 throw er; // Unhandled 'error' event ^

Error: listen EADDRINUSE: address already in use :::6001 at Server.setupListenHandle [as _listen2] (net.js:1280:14) at listenInCluster (net.js:1328:12) at Server.listen (net.js:1415:7) at Server.httpServer (/usr/local/lib/node_modules/laravel-echo-server/dist/server.js:72:20) at /usr/local/lib/node_modules/laravel-echo-server/dist/server.js:38:31 at new Promise () at Server.serverProtocol (/usr/local/lib/node_modules/laravel-echo-server/dist/server.js:31:16) at /usr/local/lib/node_modules/laravel-echo-server/dist/server.js:17:19 at new Promise () at Server.init (/usr/local/lib/node_modules/laravel-echo-server/dist/server.js:16:16) Emitted 'error' event at: at emitErrorNT (net.js:1307:8) at process._tickCallback (internal/process/next_tick.js:63:19)

vipulwalia avatar Jun 09 '21 08:06 vipulwalia

that's not the best solution, but it works so u need to change start script definition in your package.json file in docker config like this

"scripts": {
    "start": "find / -type f -name 'laravel-echo-server.lock' -delete && laravel-echo-server start"
 }

and rebuild the docker also u can try to use '/usr/src/app/' instead of '/' in find command as well or another directory set in your WORKDIR section of dockerfile, for me it works well and i'm happy)

litvinenkow avatar Jul 15 '22 19:07 litvinenkow