strapi-docker: Successful installation with Docker... But I can't access Strapi through my browser !

My install seems successful, but I can’t access through my browser. I tried every installation method possible in Docker with always the same result.

I don’t know if it is an issue or juste me >_<

1/4 The Screen I get:

image

2/4 The Installation

Tools

  • Strapi … 3.0.0-beta.19.4
  • Mango … 4.2.5
  • Mac … Mohave 10.14.6 (18G95)
  • Docker … 2.2.0.4 (43472)

Steps/Procedures (For each Docker version mentioned below)

Installation Types

Docker Latest Version w/ the guide on strapi website doc … ⛔️ Failed Docker Latest Version w/ the guide on docker strapi repo … ⛔️ Failed Docker Older version (2.0) w/ the guide on strapi website doc … ⛔️ Failed Docker Older version (2.0) w/ the guide on docker strapi repo … ⛔️ Failed CLI with SQLite … ✅ Success 🧐

  • I had to try with CLI… the problem seems to be with either Docker or the Docker Branch 😕

Url entered for the admin that point to the error page (image above)

  • localhost:1337/admin
  • 127.0.0.1:1337/admin

On the other hand, CLI installation is working…!

3/4 The docker-compose.yaml file:

Basically this file: https://github.com/strapi/strapi-docker/blob/master/examples/mongo/docker-compose.yml

services:
  strapi:
    container_name: strapi
    image: strapi/strapi
    environment:
      - DATABASE_CLIENT=mongo
      - DATABASE_HOST=db
      - DATABASE_PORT=27017
      - DATABASE_NAME=strapi
      - DATABASE_USERNAME=
      - DATABASE_PASSWORD=
      - DATABASE_AUTHENTICATION_DATABASE=strapi
    ports:
      - 1337:1337
    volumes:
      - ./app:/srv/app
    depends_on:
      - db

  db:
    container_name: mongo
    image: mongo
    environment:
      - MONGO_INITDB_DATABASE=strapi
    ports:
      - 27017:27017
    volumes:
      - ./db:/data/db
    restart: always

4/4 The Docker console output for the Strapi container:

Using strapi 3.0.0-beta.19.4
No project found at /srv/app. Creating a new strapi project
Creating a new Strapi application at /srv/app.

Creating a project from the database CLI arguments.
Creating files.
- Installing dependencies:
Dependencies installed successfully.
Your application was created at /srv/app.
Available commands in your project:
  yarn develop
  Start Strapi in watch mode.

  yarn start
  Start Strapi without watch mode.

  yarn build
  Build Strapi admin panel.
  yarn strapi
  Display all available commands.
You can start by doing:
  cd /srv/app
Starting your app...
Building your admin UI with development configuration ...
ℹ Compiling Webpack
✔ Webpack: Compiled successfully in 37.75s
 Project information
┌────────────────────┬──────────────────────────────────────────────────┐
│ Time               │ Tue Mar 31 2020 03:21:39 GMT+0000 (Coordinated … │
│ Launched in        │ 9370 ms                                          │
│ Environment        │ development                                      │
│ Process PID        │ 97                                               │
│ Version            │ 3.0.0-beta.19.4 (node v12.13.0)                  │
└────────────────────┴──────────────────────────────────────────────────┘
 Actions available
One more thing...
Create your first administrator 💻 by going to the administration panel at:
┌─────────────────────────────┐
│ http://localhost:1337/admin │
└─────────────────────────────┘
[2020-03-31T03:21:39.766Z] debug HEAD /admin (34 ms) 200
[2020-03-31T03:21:39.771Z] info ⏳ Opening the admin panel...
[2020-03-31T03:21:39.785Z] info File created: /srv/app/extensions/users-permissions/config/jwt.json

⚠️ Ps: I am totally new in these Database concepts and I am learning 😅

THANKS A LOT

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

I found the issue. It is coming from the host configuration in config/environments/{env}/server.json to run correctly in docker you will need to set it to 0.0.0.0

So I did the following and it worked for me:

  1. Standard install using mango db docker-compose in your git
  2. Changed "host": "localhost" to "host": "0.0.0.0"
  3. Went on 127.0.0.1:1337/admin/ instead of localhost:1337/admin/

So amazing! With my actual level of knowledge of the development, I would never found out that solution!

One more question! Is this solution considered as a fix, a hack or normal thing to do under docker? I am asking this as on a CLI install, localhost works fine!

Thanks

@mannp to give you full context:

In prior versions of 19.3 the host wasn’t used to set the server listening so it always defaulted to 0.0.0.0 behind the scene.

This was fixed in 19.4 but the default value became localhost and thus broke deploys on docker or other containerized envs (heroku…)

Ideally we will put localhost back for users that do not use docker and use a HOST env var inside of our docker images so the env is only changed inside docker 😃

Hope this gives you the full picture!

Just released the new docker images with a fix for this host thing when creating a new project.

Closing this issue. Feel free to comment if you still are having problems when creating a new project 😃

FYI: After changing the server.json to ‘0.0.0.0’ I had to then visit 127.0.0.1/admin to load the admin panel, NOT localhost/admin