strapi / strapi-docker

Install and run your first Strapi project using Docker

Home Page:https://strapi.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Strapi develop --watch admin Docker | Admin not found

graphicfox opened this issue · comments

Hello!

I´m new to strapi and currently trying to setup a project with docker. Everything works perfectly when I use "strapi develop" . As soon as I start "strapi develop --watch admin" i´m getting 404 under /admin/

docker-compose

version: '2'
services:
  app:
    restart: "no"
    image: '${DOCKER_BASE_IMAGE}:${DOCKER_BASE_TAG}-dev'
    container_name: '${COMPOSE_PROJECT_NAME}'
    depends_on:
      - data
      - mysql
      - import
    ports:
      - "${APP_IP}:1337:1337"
      - "${APP_IP}:8000:8000"
    env_file:
      - .env
    environment:
      - 'APP_MYSQL_HOST=${COMPOSE_PROJECT_NAME}-mysql'
    volumes:
      - ${APP_SSH_DIR}:/home/ssh-labor/.ssh
      - ${APP_WORKING_DIR}:/var/www/html
      - ${APP_LOG_DIR}:/var/www/logs
      - ${APP_OPT_DIR}/bootstrap.sh:/opt/project/bootstrap.sh
      - ${APP_OPT_DIR}/build.sh:/opt/project/build.sh
      - ${APP_OPT_DIR}/development.sh:/opt/project/development.sh
      - ${APP_OPT_DIR}/directories.sh:/opt/project/directories.sh
      - ${APP_OPT_DIR}/permissions.sh:/opt/project/permissions.sh
      - ${APP_ROOT_DIR}/.env.app:/opt/.env.app
    volumes_from:
      - data
    networks:
      - dev-network
  mysql:
    restart: "no"
    container_name: '${COMPOSE_PROJECT_NAME}-mysql'
    image: 'mariadb:10.5.10'
    env_file:
      - .env
    ports:
      - "${APP_IP}:3306:3306"
    networks:
      - dev-network
  data:
    restart: "no"
    container_name: '${COMPOSE_PROJECT_NAME}-data'
    image: ubuntu
    volumes:
      - '${APP_DATA_DIR}:/var/www/html_data'
  import:
    restart: "no"
    container_name: '${COMPOSE_PROJECT_NAME}-import'
    image: 'labordigital/import-export:latest'
    depends_on:
      - mysql
      - data
    env_file:
      - .env
    environment:
      - 'APP_MYSQL_HOST=${COMPOSE_PROJECT_NAME}-mysql'
      - MYSQL_PORT=3306
    volumes:
      - '${APP_IMPORT_DIR}:/var/www/html_import'
    volumes_from:
      - data
    networks:
      - dev-network
networks:
  dev-network:
    external: true

server.js

module.exports = ({ env }) =({
  host: '0.0.0.0',
  port: env.int('PORT', 1337),
  proxy: {
    enabled: false
  },
  admin: {
    autoOpen: false,
    host: '0.0.0.0',
    port: 8000,
    auth: {
      secret: env('ADMIN_JWT_SECRET', 'XXXXXXXXXXXXXXXXX'),
    },
  },
});

docker console

 strapi develop --watch-admin


  Project information

 ┌────────────────────┬──────────────────────────────────────────────────┐
 │ Time               │ Mon Jun 14 2021 19:47:15 GMT+0000 (Coordinated … │
 │ Launched in        │ 8066 ms                                          │
 │ Environment        │ development                                      │
 │ Process PID        │ 62                                               │
 │ Version            │ 3.6.3 (node v14.17.0)                            │
 │ Edition            │ Community                                        │
 └────────────────────┴──────────────────────────────────────────────────┘

  Actions available

 Welcome back!
 To access the server ⚡️, go to:
 http://localhost:1337

 ℹ 「wds」: Project is running at http://localhost:8000/
 ℹ 「wds」: webpack output is served from /admin/
 ℹ 「wds」: Content not from webpack is served from /var/www/html
 ℹ 「wds」: 404s will fallback to /admin/
 Starting the development server...

 Admin development at http://0.0.0.0:8000/admin/
  WARNING  Compiled with 5 warnings7:48:10 PM

I can reach the index page http://127.88.0.79:1337
But http://127.88.0.79:1337/admin throws an 404
http://127.88.0.79:8000/admin infinity loading -socket-node err_connection_refused

strapi-helper-plugin.cjs.min.js:1 GET http://localhost:1337/admin/init net::ERR_CONNECTION_REFUSED sockjs.js:1609 GET http://localhost:8000/sockjs-node/info?t=1623702954278 net::ERR_CONNECTION_REFUSED

I think that it has to do that ℹ 「wds」: Project is running at http://localhost:8000/ could be a problem. How do i tell webpack in strapi to change it to 0.0.0.0? Or has it to be the docker ip?

I just realized that my "issue" is a little bit wrong here. But if somebody needs the solution for this problem:

Solution

/config/server.js -> add url

    module.exports = ({ env }) => ({
  host: '0.0.0.0',
  port: env.int('PORT', 1337),
  url: 'http://' + env('APP_DOMAIN', '0.0.0.0') + ':' + env.int('PORT', 1337),
  admin: {
    autoOpen: false,
    host: '0.0.0.0',
    port: 8000,
    auth: {
      secret: env('ADMIN_JWT_SECRET', 'xxxxxxxxxxxxxxxxxxxxxxxxxx'),
    },
  },
});

/admin/admin.config.js -> add devserver host

module.exports = {
  webpack: (config, webpack) => {

    config.devServer = {
          host: '0.0.0.0',
      };

    return config;
  },
};