I’m new to Docker Desktop (or Docker whatsoever), the thing is that everyday my URLs don’t start my locally installed Directus. I try 0.0.0.0:8055 / 0.0.0.0:8080 / 127.0.0.1:8055 but it fails, unless I open Docker Desktop and hit play on the Directus script. Is this normal? I mean, the script needs to run all the time? I also have the issue that Docker Desktop not always opens up, and I have to end it in Task Manager first.
What’s about all those folders: Docker container usually host a single service inside a virtual machine. Data stored by this services would be lost whenever the container is restarted, so you have to map those folders to a “real” folder on your physical machine (or a folder inside a docker volume, more on this later). For the most basic setup that’s, given by your example:
MySQL service:
./mysql_data:/var/lib/mysql => persists your actual database, and more stuff you don’t have to care about
Directus service:
./uploads:/directus/uploads => persists all media you upload to directus
./extensions:/directus/extensions => persists all extensions installed in directus
The first part before the colon is the path on your physical file system, in our case relative to the location of docker-compose.yml file denoted by ./: ./mysql_data
the second part is the folder inside the virtual machine you need to persist: /var/lib/mysql
For simplicity and easy learning I would ignore docker volumes and it’s docker compose notation (they are kind of virtual harddisks for your containers) for now.
For even more simplicity, i removed the Redis cache from the services which you can add later if needed for scalability and performance.
So the most basic Directus+MySQL compose stack I can come up with is:
Since now all persisted folders are mapped to actual folders inside the compose folder, you can easy copy the compose folder over to another machine. So to pass the work on to your colleague, you simply send him the compose folder with all it’s content and all he got to do is run docker compose up -d inside of it.
Thank you Nik, not only you have provided me with the right code for a Directus+MySQL setup, but you also made me understood the logic about Directus folders and how to use Docker.
This community looks promising, I hope you will have patience for my upcoming wannabe-questions
You most likely didn’t set the restart policy on your docker container when it doesn’t start after power cycling.
Yeah, that’s most likely because Docker Desktop doesn’t close it’s frontend when the user closes it, but rather minimizes itself into the taskbar tray. Starting the app again does in that case nothing and it seems like you have to close it via task manager, although it’s already running. Watch out for that docker desktop icon in the taskbar and double click it to reopen:
I have opened the terminal inside Docker and have set docker “docker run -d --restart unless-stopped redis” but I still had to press play when opening DockerDesktop (now even on one more script “redis”), otherwise localhost wouldn’t open Directus
That’s just affecting the redis container. You have to make sure that the directus and and db (postgres/mysql/…) container are also started with an restart policy like “always” or “unless-stopped”.
It might tho be easier to orchestrate and also share your config if you move to docker-compose deployment. That way you don’t have to deal with individual container on the command line but rather set the whole stack config in one file.
@Nik, don’t go too much into technical details because I’m not a developer. :=) I’m using the tools and trying to copy/paste solutions without really knowing about alternative solutions. I’m preparing some basic Directus locally, then I’ll forward it to a dev. That said, I have tried just the command “docker run -d --restart always” but it didn’t like it: “requires at least 1 argument” (I thought that “always” was enough for an argument)
I’ll try my best:
Shut down all directus related docker containers you might have currently running via docker desktop (directus, redis, postgres, mysql…)
Create a folder somewhere on you machine
Inside that folder create a docker-compose.yml file
Paste following content into that docker-compose.yml
version: "3.8"
services:
directus:
image: directus/directus:11.12.0
container_name: directus
ports:
- "8055:8055" # Change if you want a different host port
environment:
# Must change these for first admin login
ADMIN_EMAIL: "admin@example.com" # 👈 Change to your admin email
ADMIN_PASSWORD: "password" # 👈 Change to a secure password
# Database connection — match postgres settings below
DB_CLIENT: "pg"
DB_HOST: "postgres"
DB_PORT: 5432
DB_DATABASE: "directus"
DB_USER: "directus"
DB_PASSWORD: "directus"
# Redis cache
REDIS_ENABLED: "true"
REDIS_HOST: "redis"
# Security keys — recommended to change for production
SECRET: "your-random-secret"
depends_on:
- postgres
- redis
restart: unless-stopped
volumes:
- ./directus_data/uploads:/directus/uploads
- ./directus_data/extensions:/directus/extensions
postgres:
image: postgres:16
container_name: directus_postgres
environment:
POSTGRES_DB: "directus"
POSTGRES_USER: "directus"
POSTGRES_PASSWORD: "directus"
volumes:
- ./db_data:/var/lib/postgresql/data
restart: unless-stopped
redis:
image: redis:7
container_name: directus_redis
volumes:
- ./redis_data:/data
restart: unless-stopped
volumes:
db_data:
redis_data:
Change ADMIN_EMAIL and ADMIN_PASSWORD values to your needs and save the file.
Open a terminal inside that created folder
Run docker compose up -d
Wait for the containers to spin up, then navigate your browser to http://localhost:8055
thanks but that’s exactly how I installed Directus on my PC. I have created a folder with subfolders (database, extensions, uploads) and a .yml file. My code is much simpler:
It depends what DB you wanna use and which additional settings you want or have to set.
My example is using a simply barebone Directus/Postgres/Redis with container auto restart set and I can confirm it working.
So yes, if it’s just for testing purpose use my setup, so that we can easier debug if something is not working as intended.
I have no database on my PC, I’m just building Directus on my desktop so I don’t know how it’s registering data in that folder. For the website I will use MySQL but, again, I’m just going to pass all my folders to the developer.
Pasting your code makes no difference: unless I start DockerDesktop and run the script, my URL doesn’t open up Directus.
all right, probably something was not installed properly, as I run your command and it started to install the databases (pulled), ending up with that output, plus it added some folders.
However, though I still need to open DirectusDesktop (not a big deal) in order to enable the URL, this is now showing a brand new Directus installation. Have I lost the customization I did in my first installation? (saved as the .yml copy)
Yes, because directus is now running against a different database (postgres). If you already customized Directus you would need to run against the sqlite database you had setup before again.
I need to understand what is going on. My old code was a simple one but didn’t create any folders, whereas your code has created many folders/files. By “reading” it it sounds to me that it includes several database options (postgres, redis). If I change sqlite3 the browser still shows the brand new Directus installation.
Is there just a code that is MySQL ready?
(sorry for dumb questions)
UPDATE: I found this, Let me see if it works. It doesn’t matter I lost the previous data, it was just some settings….