Docker, MySQL - Error 1045, Access denied for use root - docker

I've just started learning docker and I want to dockerize my Golang project but I get this error when I want to use MySQL: Error 1045: Access denied for use 'root'#'192.168.32.3' (using password: YES).
Here is my docker-compose.yml:
version: '3.1'
services:
x-media-service:
build: .
restart: always
ports:
- 8000:8000
links:
- db
environment:
- "DB_PORT=3306"
- "DB_HOST=db"
- "DB_NAME=xmedia"
- "DB_PASS=password"
- "JWT_SECRET=secret"
- VIDEO_DIR=/data/movies
- MOVIES_SUB_DIR=/data/sub
volumes:
- /home/user/Movies:/data/movies
- /home/user/Movies/sub:/data/sub
db:
image: mysql:5.7
ports:
- 6603:3306
environment:
- "MYSQL_ROOT_PASSWORD=root"

There are a couple of questions with your docker-compose.yaml:
Does your database server have a database called xmedia?
What is the intent with JWT_SECRET
I think that links: - db is redundant
I find adminer useful to debug MySQL|MariaDB database stuff. adminer is a tool that I've found recommended elsewhere and I'm sure there are others that are similar.
Example:
version: '3.1'
services:
# x-media-service:
# build: .
# restart: always
# ports:
# - 8000:8000
# links:
# - db
# environment:
# - "DB_PORT=3306"
# - "DB_HOST=db"
# - "DB_NAME=xmedia"
# - "DB_PASS=password"
# - "JWT_SECRET=secret"
# - VIDEO_DIR=/data/movies
# - MOVIES_SUB_DIR=/data/sub
# volumes:
# - /home/user/Movies:/data/movies
# - /home/user/Movies/sub:/data/sub
# For Debugging
adminer:
depends_on:
- db
image: adminer:4.7.2
ports:
- 7777:8080
db:
image: mysql:5.7
ports:
- 6603:3306
environment:
- "MYSQL_ROOT_PASSWORD=root"
then browse http://localhost:7777, and login using username root and password root (per your spec)
Then, by default (of course) I don't have xmedia and suspect you do not either:

In my Go code I'm using root user to login into MySQL. I changed DB_PASS in x-media-service to same as MYSQL_ROOT_PASSWORD in db service. Now everything is working.

Related

How do I fix my docker-compose.yml? - Unsupported config option for services.teslamate: 'database'

I am new to this today. I have been trying to figure out what the problem is all day.
docker-compose version 1.28.5, build 324b023a
I run:
docker-compose up -d
and I get:
ERROR: The Compose file './docker-compose.yml' is invalid because:
Unsupported config option for services.teslamate: 'database'
version: "3"
services:
teslamate:
image: teslamate/teslamate
restart: always
environment:
- ENCRYPTION_KEY= <Insert Key>
- DB_USER=teslamate
- DB_PASS= <Insert password>
- DB_NAME=teslamate
- DB_HOST=database
- MQTT_HOST=mosquitto
- VIRTUAL_HOST=<Insert IP address>
# if you're going to access the UI from another machine replace
# "localhost" with the hostname / IP address of the docker host.
- TZ=US # (optional) replace to use local time in debug logs. See "Configuration".
ports:
- 4000:4000
volumes:
- ./import:/opt/app/import
cap_drop:
- all
database:
image: postgres:14
restart: always
environment:
- POSTGRES_USER=teslamate
- POSTGRES_PASSWORD= <Insert password>
- POSTGRES_DB=teslamate
volumes:
- teslamate-db:/var/lib/postgresql/data
grafana:
image: teslamate/grafana
restart: always
environment:
- DATABASE_USER=teslamate
- DATABASE_PASS= goforit
- DATABASE_NAME=teslamate
- DATABASE_HOST=database
ports:
- 3000:3000
volumes:
- teslamate-grafana-data:/var/lib/grafana
mosquitto:
image: eclipse-mosquitto:2
restart: always
command: mosquitto -c /mosquitto-no-auth.conf
# ports:
# - 1883:1883
volumes:
- mosquitto-conf:/mosquitto/config
- mosquitto-data:/mosquitto/data
volumes:
teslamate-db:
teslamate-grafana-data:
mosquitto-conf:
mosquitto-data:
Could someone please let me know what is wrong?
Thank you,
It is just a Yaml indentation problem. Your services teslamate, database, grafana and mosquito needs to have the same indentation, otherwise database is seen as a property of teslamate and it is not a valid property for docker-compose.
version: "3"
services:
teslamate:
image: teslamate/teslamate
restart: always
environment:
- ENCRYPTION_KEY= <Insert Key>
- DB_USER=teslamate
- DB_PASS= <Insert password>
- DB_NAME=teslamate
- DB_HOST=database
- MQTT_HOST=mosquitto
- VIRTUAL_HOST=<Insert IP address>
# if you're going to access the UI from another machine replace
# "localhost" with the hostname / IP address of the docker host.
- TZ=US # (optional) replace to use local time in debug logs. See "Configuration".
ports:
- 4000:4000
volumes:
- ./import:/opt/app/import
cap_drop:
- all
database:
image: postgres:14
restart: always
environment:
- POSTGRES_USER=teslamate
- POSTGRES_PASSWORD= <Insert password>
- POSTGRES_DB=teslamate
volumes:
- teslamate-db:/var/lib/postgresql/data
grafana:
image: teslamate/grafana
restart: always
environment:
- DATABASE_USER=teslamate
- DATABASE_PASS= goforit
- DATABASE_NAME=teslamate
- DATABASE_HOST=database
ports:
- 3000:3000
volumes:
- teslamate-grafana-data:/var/lib/grafana
mosquitto:
image: eclipse-mosquitto:2
restart: always
command: mosquitto -c /mosquitto-no-auth.conf
# ports:
# - 1883:1883
volumes:
- mosquitto-conf:/mosquitto/config
- mosquitto-data:/mosquitto/data
volumes:
teslamate-db:
teslamate-grafana-data:
mosquitto-conf:
mosquitto-data:

nextcloud can't create an admin user

error while trying to create the admin user:
Error while trying to create admin user: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [1045] Access denied for user 'nextcloud'#'172.22.0.6' (using password: YES)
docker-compose.yml
version: '3'
volumes:
nextcloud-data:
nextcloud-db:
networks:
nginx_network:
external: true
services:
app:
image: nextcloud
restart: always
volumes:
- nextcloud-data:/var/www/html
environment:
- MYSQL_PASSWORD=test
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_HOST=db
networks:
- nginx_network
db:
image: mariadb
restart: always
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
volumes:
- nextcloud-db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=test
- MYSQL_PASSWORD=test
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
networks:
- nginx_network
I couldn't find any similar problems with a solution that works for me and the docker compose seems okay to me
Solution that worked for me:
changed database container's name
deleted all the volumes
DO NOT SET THE USER AS ROOT normal user is enough
(also this error shows up if you mistype your credentials between containers)

Permission issue with WordPress docker setup

I am trying to setup a WordPress project on my machine using Docker. This is my docker-compose.yml file code:
version: "3"
services:
# Database
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
networks:
- wp
# Web Server
wordpress:
ports:
- "4000:80"
depends_on:
- db
image: wordpress:latest
restart: always
volumes:
- "./html/:/var/www/html/"
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
networks:
- wp
networks:
wp:
volumes:
db_data:
This works fine but what it does is, that the files that are mounted inside ./html folder has user and group permission assigned as www-data:www-data. I am working on Ubuntu desktop OS. So every time I try to update any code inside ./html folder, I get permission denied message.
Is there any way I can fix this issue?
I have tried this command to add my user to www-data group but that didn't work aswell.
sudo usermod -aG www-data aslam
Try to match the user's id on the host machine to match that of www-data inside the container or vice-versa. May be read this for more info and howto.
To be clear for everyone else, adding user: 0:0 to the docker-compose.yml file solved this issue for me too.
There isn't a problem with file permissions when you mount the files on windows... but I feel like mounting to Windows isn't a good idea because the response time to the application is very slow that way.
Here's the full docker-compose.yml
Running this in your WSL of choice will prevent the permissions issues.
version: '3.3'
services:
wptoolkit:
# add user declaration to avoid windows permission issues when editing files and folders through your favorite editor
user: 0:0
# Ensure DB is up
depends_on:
- db
# We'll use the most recent Wordpress install
image: wordpress:latest
# Map files from container back to linux at this directory location
volumes:
- ./:/var/www/html
ports:
# We'll access our site on http://localhost:8999
- "80:80"
restart: always
environment:
# We'll provide some SQL credentials -- these match what's
# in our db section
- WORDPRESS_DB_HOST=db
- WORDPRESS_DB_USER=wordpress
- WORDPRESS_DB_PASSWORD=wordpress
- WORDPRESS_DB_NAME=wordpress
# This is our MySQL database server
db:
# We use a mariadb image which supports both amd64 & arm64 architecture
image: mariadb:10.6.4-focal
# If you really want to use MySQL, uncomment the following line
#image: mysql:8.0.27
command: '--default-authentication-plugin=mysql_native_password'
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
- MYSQL_ROOT_PASSWORD=wordpress
- MYSQL_DATABASE=wordpress
- MYSQL_USER=wordpress
- MYSQL_PASSWORD=wordpress
expose:
- 3306
- 33060
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: pma
links:
- db
environment:
PMA_HOST: db
PMA_PORT: 3306
PMA_ARBITRARY: 1
restart: always
ports:
- 8081:80
volumes:
db_data:

yml docker-compose error mapping values are not allowed here

I try to learn about container, but i have a problem with my docker-compose.yml file, after i run the docker compose up, i always get the same error:
"ERROR: yaml.scanner.ScannerError: mapping values are not allowed
here"
even if i changed the mount path to docker volume, i got the same error, this is my yml file
version: "3"
services:
database:
image: mariadb
ports:
- "3260:3260"
volumes:
- /home/randy/Desktop/Latihan/wordpress-mariadb/mariadb:var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
wordpress:
image: wordpress
ports:
- "2000:80"
volumes:
- /home/randy/Desktop/Latihan/wordpress-mariadb/wordpress:/var/www/html
environment:
WORDPRESS_DB_PASSWORD: root
depends_on:
- database
links:
- database
It appears that your yaml is invalid. When I face these types of issues, what I will do is use a site called http://www.yamllint.com/ which will validate the syntax for you.
This yaml based on your example is valid:
Note: You can use 4 spaces (or 2 which I prefer), but never use tabs.
version: "3"
services:
database:
environment:
MYSQL_ROOT_PASSWORD: root
image: mariadb
ports:
- "3260:3260"
volumes:
- "/home/randy/Desktop/Latihan/wordpress-mariadb/mariadb:var/lib/mysql"
wordpress:
image: wordpress
ports:
- "2000:80"
volumes:
- /home/randy/Desktop/Latihan/wordpress-mariadb/wordpress:/var/www/html
environment:
WORDPRESS_DB_PASSWORD: root
depends_on:
- database
links:
- database

How do I build and run api-platform image to a production docker container?

I have followed the api-platform tutorial and successfully built and started the application using Docker on my localhost machine.
I have a production server running Ubuntu 16.04.5 LTS, and a newly installed Docker version 18.06.1-ce.
How would I build this code on my local machine and run it on the Docker server?
I have also looked at the Deploying API Platform Applications documentation but I am not sure how to use this.
I am struggling to understand how to build api-platform from my localhost to the server
this is docker-compose.yml file try this please docker-compose up -d
version: '3.4'
services:
php:
image: ${CONTAINER_REGISTRY_BASE}/php
build:
context: ./api
target: api_platform_php
cache_from:
- ${CONTAINER_REGISTRY_BASE}/php
- ${CONTAINER_REGISTRY_BASE}/nginx
- ${CONTAINER_REGISTRY_BASE}/varnish
depends_on:
- db
# Comment out these volumes in production
volumes:
- ./api:/srv/api:rw,cached
# If you develop on Linux, uncomment the following line to use a bind-mounted host directory instead
# - ./api/var:/srv/api/var:rw
api:
image: ${CONTAINER_REGISTRY_BASE}/nginx
build:
context: ./api
target: api_platform_nginx
cache_from:
- ${CONTAINER_REGISTRY_BASE}/php
- ${CONTAINER_REGISTRY_BASE}/nginx
- ${CONTAINER_REGISTRY_BASE}/varnish
depends_on:
- php
# Comment out this volume in production
volumes:
- ./api/public:/srv/api/public:ro
ports:
- "8080:80"
cache-proxy:
image: ${CONTAINER_REGISTRY_BASE}/varnish
build:
context: ./api
target: api_platform_varnish
cache_from:
- ${CONTAINER_REGISTRY_BASE}/php
- ${CONTAINER_REGISTRY_BASE}/nginx
- ${CONTAINER_REGISTRY_BASE}/varnish
depends_on:
- api
volumes:
- ./api/docker/varnish/conf:/usr/local/etc/varnish:ro
tmpfs:
- /usr/local/var/varnish:exec
ports:
- "8081:80"
db:
# In production, you may want to use a managed database service
image: postgres:10-alpine
environment:
- POSTGRES_DB=api
- POSTGRES_USER=api-platform
# You should definitely change the password in production
- POSTGRES_PASSWORD=!ChangeMe!
volumes:
- db-data:/var/lib/postgresql/data:rw
# You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
# - ./docker/db/data:/var/lib/postgresql/data:rw
ports:
- "5432:5432"
client:
# Use a static website hosting service in production
# See https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#deployment
image: ${CONTAINER_REGISTRY_BASE}/client
build:
context: ./client
cache_from:
- ${CONTAINER_REGISTRY_BASE}/client
env_file:
- ./client/.env
volumes:
- ./client:/usr/src/client:rw,cached
- /usr/src/client/node_modules
ports:
- "80:3000"
admin:
# Use a static website hosting service in production
# See https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#deployment
image: ${CONTAINER_REGISTRY_BASE}/admin
build:
context: ./admin
cache_from:
- ${CONTAINER_REGISTRY_BASE}/admin
volumes:
- ./admin:/usr/src/admin:rw,cached
- /usr/src/admin/node_modules
ports:
- "81:3000"
h2-proxy:
# Don't use this proxy in prod
build:
context: ./h2-proxy
depends_on:
- client
- admin
- api
- cache-proxy
ports:
- "443:443"
- "444:444"
- "8443:8443"
- "8444:8444"
volumes:
db-data: {}

Resources