Skip to content
Advertisement

Can’t access Adonis from Docker Container

I use Docker to contain my Adonis app. The build was success but when I access the app, I got ERR_SOCKET_NOT_CONNECTED or ERR_CONNECTION_RESET.

My docker compose contains adonis and database. Previously, I use the setup similar with this for my expressjs app, and it has no problem.

The adonis .env is remain standard, modification.

This is my setup:

# docker-compose.yml

version: '3'
services:
  adonis:
    build: ./adonis
    volumes:
      - ./adonis/app:/usr/src/app
    networks:
      - backend
    links:
      - database
    ports:
      - "3333:3333"
  
  database:
    image: mysql:5.7
    ports:
      - 33060:3306
    networks:
      - backend
    environment:
      MYSQL_USER: "user"
      MYSQL_PASSWORD: "root"
      MYSQL_ROOT_PASSWORD: "root"

  networks:
    backend:
      driver: bridge
# adonis/Dockerfile

FROM node:12-alpine

RUN npm i -g @adonisjs/cli

RUN mkdir -p /usr/src/app

WORKDIR /usr/src/app

COPY ./app/. .

RUN npm install

EXPOSE 3333

CMD ["adonis", "serve", "--dev"]  

I couldn’t spot anything wrong with my setup.

Advertisement

Answer

The serve command starts the HTTP server on the port defined inside the .env file in the project root.

You should have something like this(note that HOST has to be set to 0.0.0.0 instead of localhost to accept connections from the outside):

HOST=0.0.0.0
PORT=3333
APP_URL=http://${HOST}:${PORT}
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement