Docker - Unauthorized in MariaDB - docker

I want to create a simply LAMP with docker. The code is
Dockerfile
FROM php:8.0.0-apache
ARG DEBIAN_FRONTEND=noninteractive
RUN docker-php-ext-install mysqli
RUN apt-get update \
&& apt-get install -y libzip-dev \
&& apt-get install -y zlib1g-dev \
&& rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-install zip
RUN a2enmod rewrite
Docker Compose
version: "3.8"
services:
www:
build: .
container_name: 'www'
hostname: 'laravelvue.com'
restart: 'always'
ports:
- "80:80"
networks:
- default
volumes:
- ./www:/var/www/html
database:
image: mariadb:10.7.1
container_name: 'mariadb'
command: --default-authentication-plugin=mysql_native_password
restart: 'always'
ports:
- "3306:3306"
volumes:
- persistent:/var/lib/mysql
environment:
MARIADB_DATABASE: laravelvue
MARIADB_USER: root
MARIADB_PASSWORD: test
MARIADB_ROOT_PASSWORD: test
networks:
- default
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: 'phpmyadmin'
links:
- database
environment:
MYSQL_USER: root
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
ports:
- 8000:80
volumes:
persistent:
When i launch docker compose up -d works, but when i try to enter in database (localhost:8000) with username root and password test returns
mysqli::real_connect(): (HY000/2002): php_network_getaddresses:
getaddrinfo failed: Temporary failure in name resolution
I´m new with docker so i don´t know exactly what´s is wrong ¿Anybody see what´s wrong?

Docker networking works with the name of your service as hostname. So in your database service you can connect with your phpmyadmin via http://phpmyadmin:8000. The same is for the other services. In your phpadmin service you connect with your database via http://database:3306.
And remove the networks: default and links: database in your docker-compose.yml it is not needed, as you use version 3.8 in docker-compose.yml. And make sure your phpadmin service depends_on your database service.
Correct docker-compose.yml:
version: "3.8"
services:
www:
build: .
container_name: 'www'
restart: 'always'
ports:
- "80:80"
volumes:
- ./www:/var/www/html
database:
image: mariadb:10.7.1
container_name: 'mariadb'
command: --default-authentication-plugin=mysql_native_password
restart: 'always'
ports:
- "3306:3306"
volumes:
- persistent:/var/lib/mysql
environment:
MARIADB_DATABASE: laravelvue
MARIADB_USER: root
MARIADB_PASSWORD: test
MARIADB_ROOT_PASSWORD: test
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
depends_on:
- database
environment:
MYSQL_USER: root
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
ports:
- 8000:80

Related

Docker Compose Adminer

I want to use the adminer image that is raised with the following docker command:
docker run \
--rm
-p 8000:80
-e MEMORY=512M
-e UPLOAD=4096M
dockette/adminer:full
My docker-compose.yml is as follows:
version: '2.4'
services:
mariadb:
container_name: mariadb-prueba
image: mariadb
restart: always
volumes:
- ./mariadb-data:/var/lib/mysql
environment:
MYSQL_DATABASE: 'db_prueba'
MYSQL_USER: 'admin'
MYSQL_PASSWORD: 'admin'
MARIADB_ROOT_PASSWORD: 'admin'
ports:
- 2000:3306
adminer:
container_name: adminerprueba
image: dockette/adminer
restart: always
ports:
- 8000:80
environment:
- UPLOAD=4096M
- MEMORY=512M
volumes:
mariadb-data:
The problem is that it runs but when I do localhost:8000 the system appears to be down.
Am I missing something in the docker-compose

Docker compose Unable to connect

I've created docker-compose.yml file with the following content. My docker service runs ok, docker run hello-world works just fine and after running command
docker-compose build && docker-compose up -d
I see no errors but in the browser I'm getting an error Unable to connect when I go to localhost:8000
version: '3'
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
ports:
- "8000:80"
depends_on:
- php
- mysql
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
volumes:
- ./src:/var/www/html
ports:
- "9000:9000"
mysql:
image: mysql:8.0
container_name: mysql
restart: unless-stopped
ports:
- "3306:3306"
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_DATABASE: db
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: root
SERVICE_NAME: mysql
When I run command
docker-compose exec php ls
I can see the list of files and folders

Running out of memory when executing composer inside a docker container

I'm running composer on docker container and I'm trying to install predis so I run the command
docker-compose run --rm composer require predis/predis
But I get this error
Can someone explain me how to fix?
that's my dockerfile
FROM php:7.2-fpm-alpine
RUN docker-php-ext-install pdo pdo_mysql
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version
and that's my docker-compose
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
ports:
- "8088:80"
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- mysql
- php
networks:
- laravel
mysql:
image: mysql:5.7.22
container_name: mysql
restart: unless-stopped
tty: true
ports:
- "4306:3306"
environment:
MYSQL_DATABASE: homestead
MYSQL_USER: homestead
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: secret
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- laravel
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
volumes:
- ./src:/var/www/html
ports:
- "9000:9000"
networks:
- laravel
redis:
image: redis:5.0.0-alpine
restart: always
container_name: redis
ports:
- "6379:6379"
networks:
- laravel
In your docker-compose file, add an environment entry with COMPOSER_MEMORY_LIMIT: -1 to your php service
So your php services look like -
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
volumes:
- ./src:/var/www/html
environment:
COMPOSER_MEMORY_LIMIT: -1
ports:
- "9000:9000"
networks:
- laravel

docker services.web.working_dir contains an invalid type, it should be a string

I am trying to up phpserver via docker-compose.
I put 3 files in my working directory.
.env
docker-compose.yml
Dockerfile
.env
##PATHS
DB_PATH_HOST=./databases
APP_PATH_HOST=./blog
APP_PATH_CONTAINER=/var/www/html/
MYSQL_ROOT_PASSWORD=123456
docker-compose.yml
version: '3'
services:
web:
build: .
environment:
- APACHE_RUN_USER=www-data
volumes:
- ${APP_PATH_HOST}: ${APP_PATH_CONTAINER}
ports:
- 8080:80
working_dir:
- ${APP_PATH_CONTAINER}
db:
image: mariadb
restart: always
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
volumes:
- ${DB_PATH_HOST}: /var/lib/mysql
adminer:
image: adminer
restart: always
ports:
- 6080:8080
composer:
image: composer:1.7
volumes:
- ${APP_PATH_HOST}: ${APP_PATH_CONTAINER}
working_dir: ${APP_PATH_CONTAINER}
command: composer install
and Dockerfile
FROM php:7.2-apache
RUN docker-php-ext-install \
pdo_mysql \
&& a2enmod
rewrite
But after I try to run
docker-compose up --build
I have the problem
ERROR: The Compose file '.\docker-compose.yml' is invalid because:
services.web.working_dir contains an invalid type, it should be a string
services.composer.volumes contains an invalid type, it should be a string
services.web.volumes contains an invalid type, it should be a string
services.db.volumes contains an invalid type, it should be a string
I tried to change docker-compose file version to 2 - does not work
I tried to use '' and "" the same problem.
I want to run my server successfully.
The following two formats work:
Format #1
environment:
MYSQL_ROOT_PASSWORD: rootpassword
Format #2
environment:
- MYSQL_ROOT_PASSWORD=rootpassword
version: "3.3"
services:
web:
build: .
environment:
- APACHE_RUN_USER=www-data
volumes:
- "${APP_PATH_HOST}: ${APP_PATH_CONTAINER}"
ports:
- 8080:80
working_dir: ${APP_PATH_CONTAINER}
db:
image: mariadb
restart: always
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
volumes:
- "${DB_PATH_HOST}:/var/lib/mysql"
adminer:
image: adminer
restart: always
ports:
- 6080:8080
composer:
image: composer:1.7
volumes:
- "${APP_PATH_HOST}: ${APP_PATH_CONTAINER}"
working_dir: ${APP_PATH_CONTAINER}
command: composer install
What you used for working_dir was a list. It needed a string.
I want to connect to from adminer to postgres
version: '3'
services:
web:
build: .
environment:
- APACHE_RUN_USER=www-data
volumes:
- ./blog:/var/www/html/
ports:
- 8080:80
working_dir: /var/www/html/
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: kisphp
POSTGRES_USER: root
POSTGRES_DB: kisphp
ports:
- "5432:5432"
volumes:
- ./postgres:/var/lib/postgresql/data
adminer:
image: adminer
restart: always
ports:
- "6080:8080"
and I have next error.
SQLSTATE[08006] [7] FATAL: password authentication failed for user "root"

Docker connect database from a container (laravel) to other container (wordpress)

I have two project using docker, in first project is laravel, and second is wordpress. In laravel I want to connect both database (to convert laravel database to wordpress database).
but I don't know how to connect it:
here is two docker-compose.yml file:
in laravel:
version: '2'
services:
# The Application
app:
build:
context: ./
dockerfile: app.dockerfile
working_dir: /var/www
volumes:
- ./:/var/www
environment:
- "DB_PORT=3306"
- "DB_HOST=database"
# The Web Server
web:
build:
context: ./
dockerfile: web.dockerfile
working_dir: /var/www
volumes_from:
- app
ports:
- 8081:80
# The Database
database:
image: mysql:5.6
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_DATABASE=homestead"
- "MYSQL_USER=homestead"
- "MYSQL_PASSWORD=secret"
- "MYSQL_ROOT_PASSWORD=secret"
ports:
- "33061:3306"
volumes:
dbdata:
and my docker-compose.yml file in wordpress:
version: '2'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: wpshop
MYSQL_USER: root
MYSQL_PASSWORD: 123456
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- ./:/var/www/html
ports:
- "8080:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: 123456
volumes:
db_data:
I cd to each project and run docker-compose up -d
Please help me!
Create an external network and use that network as default network for all your containers. This way you'll be able to reach all container by its name.
Take a look to Docker container networking: https://docs.docker.com/engine/userguide/networking/

Resources