I'm trying to setup a Drupal site template however I have an issue, this is my current docker-compose:
version: '2'
services:
database:
image: mysql
container_name: database
command: mysqld --user=root --verbose
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: "db"
MYSQL_USER: "user"
MYSQL_PASSWORD: "pass"
MYSQL_ROOT_PASSWORD: "root"
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
restart: always
site:
image: drupal
container_name: site
ports:
- "555:80"
volumes:
- ./drupal:/var/www/html
links:
- database:database
working_dir: /app
restart: always
volumes:
db:
Now if I do that the site doesn't work, no files are in the /var/www/html directory and the site 404's on everything. However if I remove the volume in the site container, it works perfectly and I can start setting it up as if it was a regular site.
What am I missing?
When you don't map a volume in the site service, that means Drupal is using whatever's already in /var/www/html from the drupal image. When you map the volume, you're overwriting /var/www/html with whatever's in ./drupal on the host machine. The results you're seeing imply there may be something wrong with the contents of ./drupal. To start with, I would run the service without mapping a volume and then copy the exact contents of /var/www/html into your local folder:
docker cp compose_site_1:/var/www/html/ ./drupal
Then try running the service again, this time with the volume mapped and see if that works. If it works, that tells you the problem was with the contents of ./drupal.
Related
I have MariaDB on docker
Trying to setup ssl I managed to completely break my user; I ended up with user duplicates and a new user called testssl
I tried resetting everything by deleting my database; deleting the image but nothing works. Every time I connect to the database and list users I get the same old list; testssl is still there
Where are those settings stored and how do I reset MariaDB to a completely clean state on my docker?
app:
container_name: app
image: "${APP_IMAGE}"
restart: always
build: build/app
env_file: .env
networks:
- app_network
volumes:
- "${APP_HOST_DIR}:${APP_CONTAINER_DIR}"
depends_on:
- database
database:
container_name: mariadb
image: "mariadb:${MARIADB_VERSION}"
restart: always
env_file: .env
volumes:
- "${SQL_INIT}:/docker-entrypoint-initdb.d"
- type: bind
source: ${MARIADB_DATA_DIR}
target: /var/lib/mysql
- type: bind
source: ${MARIADB_LOG_DIR}
target: /var/logs/mysql
- type: bind
source: ${MARIADB_CERTS_DIR}
target: /etc/certs/
environment:
MYSQL_ROOT_PASSWORD: "${MYSQL_ROOT_PASSWORD}"
MYSQL_DATABASE: "${MYSQL_DATABASE}"
MYSQL_USER: "${MYSQL_USER}"
MYSQL_PASSWORD: "${MYSQL_PASSWORD}"
.env
MARIADB_DATA_DIR=./build/database/files/database
MARIADB_LOG_DIR=./build/database/files/logs
MARIADB_CERTS_DIR=./build/database/certs
MariaDB stores all of its runtime configuration (users, databases, etc.) in its data directory.
You've told your MariaDB container to use the host build/database/files/database directory for its data, so resetting the container won't do much since the data is, well, there.
Assuming the container is well-behaved and will initialize the database system if there's nothing in the data directory, you should be able to move that build/database/files/database folder to e.g. build/database/files/database.old, and create a new empty build/database/files/database, then retry.
If you are using docker volumes you can:
Rename the docker volume
From
mariadb:
image: mariadb:10.6.11
...
volumes:
- mysqldataprevious:/var/lib/mysql
...
To
mariadb:
image: mariadb:10.6.11
...
volumes:
- mysqldatanew:/var/lib/mysql
...
Restart docker services
docker-compose up -d
Remove previous volume (optional)
docker volume prune
This will install a fresh mariadb in the new volume and with docker volume prune if your previous volume is not used by another container it will be deleted
I'm trying to make a Symfony project running in docker container.
So, there is my docker-compose.yml :
version: '3.7'
services:
mariadb:
image: ${MARIADB_VERSION}
restart: on-failure
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
ports:
- ${PORTS_MARIADB}
volumes:
- './db/:/var/lib/mysql'
php:
build:
context: .
dockerfile: docker/php/Dockerfile
volumes:
- './app/:/usr/src/app'
restart: on-failure
user: 1000:1000
nginx:
image: ${NGINX_VERSION}
restart: on-failure
volumes:
- './app/public/:/usr/src/app'
- './docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro'
ports:
- ${PORTS_NGINX}
depends_on:
- php
I start my container like this (with non-root user):
docker-compose build
docker-compose up -d
So, at this point, all is ok but, If I want to re-build my docker container:
docker-compose down
docker-compose build
The volume ./db (of mariadb) have his permissions set to systemd-coredump:findl users (findl is mine)
So, I have this error when I try to build the container:
Why the permissions to the volume /db are set to another user... ?
Regards
As a result of this Github issue reply, I was able to fix my issues and move on. Basically, take the temporary portion of your volume and add it to .dockerignore. The commenter does a much better explanation of why it works than I would ever be able to muster here, but if this gets you (or anyone else who runs into this issue) farther along, then so be it.
I'm trying to run mysql under container with mysql parameters i defined on docker-compose.yml file. But i have an access denied when i run :
mysql -utest -ptest
I'm only able to connect with mysql -uroot -proot.
Help me please.
Thanks.
mysql:
container_name: mysql
image: mysql
restart: always
volumes:
- .docker/data/db:/var/lib/mysql
environment:
MYSQL_DATABASE: app
MYSQL_ROOT_PASSWORD: test
MYSQL_USER: test
MYSQL_PASSWORD: test
Try to launch with specified database name like this:
mysql -u test -p test app
Explanation:
MYSQL_USER, MYSQL_PASSWORD
These variables are optional, used in conjunction to create a new user and to set that user's password. This user will be granted superuser permissions (see above) for the database specified by the MYSQL_DATABASE variable. Both variables are required for a user to be created.
From MySQL docker hub page
Permissions are granted only for the database specified by environment variable. When you try to log into default database you have no permissions to it only for app database.
My complete docker-compose file.
version: '3.2'
services:
apache:
container_name: apache
build: .docker/apache/
restart: always
volumes:
- .:/var/www/html/app/
ports:
- 80:80
depends_on:
- php
- mysql
links:
- mysql:mysql
php:
container_name: php
build: .docker/php/
restart: always
volumes:
- .:/var/www/html/app/
working_dir: /var/www/html/app/
mysql:
container_name: mysql
image: mysql
restart: always
volumes:
- .docker/data/db:/var/lib/mysql
environment:
MYSQL_DATABASE: app
MYSQL_ROOT_PASSWORD: test
MYSQL_USER: test
MYSQL_PASSWORD: test
Maybe you could try attaching an interactive bash process to the already running container by following these steps:
Get your container id or name from running docker container ls in your terminal (I'm talking about the mysql container, which should have the mysql name according to your docker-compose.yml file)
Run docker exec -it mysql bash to associate an interactive bash process to the running container
Now, being inside of your container's filesystem, run mysql --user=test --password=test and you should be able to get on with your work
I have the following docker-compose.yml file:
version: '3'
services:
maria_service:
build: ./db_maria
restart: always
environment:
MYSQL_DATABASE: mariadb
MYSQL_USER: joel
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
volumes:
- ./db:/var/lib/mysql
drupal_service:
build: ./website
restart: always
ports:
- 8080:80
volumes:
- /var/www/html/modules
- /var/www/html/profiles
- /var/www/html/themes
# this takes advantage of the feature in Docker that a new anonymous
# volume (which is what we're creating here) will be initialized with the
# existing content of the image at the same location
- /var/www/html/sites
depends_on:
- maria_service
Here's my working directory:
Here's the drupal dockerfile where all I'm doing is to pull the drupal image:
Here's the mariadb dockerfile:
It automatically generate this "db" subfolder seen in the pic below:
My issue is everytime I enter mariadb on the drupal UI at localhost:8080, it throws this error below:
UPDATES:
Based on #Tarun Lalwani answer, my issue was that, in the Drupal UI, I would enter my username, password and db name but if you expand that Advanced Options in that Drupal screenshot, you'll see that the HOSTNAME was pointing to "localhost" when it should be pointing to the actual hostname of the mariadb database server which in DOCKER WORLD, the hostname name of a running container is ITS SERVICE NAME i.e "mariadb_service" as seen in the docker-compose.yml file - see screenshot. Hope I wasn't the only newbie that bumped into that and will help others, thanks Tarun Lalwani!!
You need to set the Host name also for the DB in Drupal. This db host will be maria_service as per the service name from your docker-compose.yml file. This needs to be done by expanding the Advanced options
Using Environment Variables
You could also try setting the environment variables for these settings
version: '3'
services:
maria_service:
build: ./db_maria
restart: always
environment:
MYSQL_DATABASE: mariadb
MYSQL_USER: joel
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
volumes:
- ./db:/var/lib/mysql
drupal_service:
build: ./website
restart: always
ports:
- 8080:80
volumes:
- /var/www/html/modules
- /var/www/html/profiles
- /var/www/html/themes
# this takes advantage of the feature in Docker that a new anonymous
# volume (which is what we're creating here) will be initialized with the
# existing content of the image at the same location
- /var/www/html/sites
depends_on:
- maria_service
environment:
DB_HOST: maria_service
DB_USER: joel
DB_PASSWORD: password
DB_NAME: mariadb
DB_DRIVER: mysql
My own_app requires a MySQL database. The problem is that the own_app container needs to ip of the MySQL database. My aim is to solve this issue by using docker-compose.yml.
Dockerfile
ENTRYPOINT ["docker-entrypoint.sh"]
docker-compose.yml
Based on the Wordpress example the docker-compose.yml has been slightly modified as follows:
version: '2'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
own_app:
depends_on:
- db
image: own_app:latest
ports:
- "8000:80"
restart: always
environment:
MYSQL_DB_HOST: db:3306
volumes:
db_data:
but it inserts db:3306
db.default.url="jdbc:mysql://db:3306/database_name"
instead of an IP address
Problem
The sed statement that resides in the docker-entrypoint.sh works well, i.e. it replaces localhost with the $MYSQL_DB_HOST environment variable. The problem is that docker-compose returns db:3306 instead of <ip>:3306
Question
Why is docker-compose not looking up the IP address?
Environment variables in docker-compose are just strings, it doesn't know if it's a hostname or any other text. The only parsing that's done is to expand variables in the ${varname} syntax.
For connecting containers together, you don't want IP addresses anyway, they can change. Use the DNS based discovery which will resolve "db" from the service name in any other containers that are on the same network.