I have a MariaDB Docker container that I want to access automatically with the help of a bash script.
I'm using Docker compose:
version: '3'
services:
drupal:
image: jonasvbogaert/php-docker:${IMAGE_VERSION}
container_name: drupalenv
ports:
- 8080:80
volumes:
- /var/www/html/
restart: always
environment:
DRUPAL_SITE_NAME: Drupal
DRUPAL_USER: admin
DRUPAL_PASS: admin
mariadb:
image: mariadb:latest
container_name: mariadbenv
restart: always
ports:
- 3036:3036
depends_on:
- drupal
environment:
MYSQL_ROOT_PASSWORD: ""
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_USER: drupal
MYSQL_PASSWORD: drupal
MYSQL_DATABASE: drupal`
The first command is to dive in the container (works fine):
docker exec -it mariadbenv bash
But the second one:
mysql
outputs the following error:
ERROR 1045 (28000): Access denied for user 'jonasvb'@'localhost' (using password: NO)
the input device is not a TTY
When I enter "mysql" myself, it works.
This is the script I use:
function main () {
getUserInput
}
function fireDocker () {
if [ $DRUPAL_VERSION = "7" ]; then
IMAGE_VERSION="drupal7"
export IMAGE_VERSION
docker-compose up -d
mountDump
else
IMAGE_VERSION="drupal8"
export IMAGE_VERSION
docker-compose up -d
mountDump
fi
}
function getUserInput () {
echo "Enter Drupal version (7 or 8)"
read DRUPAL_VERSION # Read
fireDocker $DRUPAL_VERSION
}
function mountDump(){
docker exec -it mariadbenv bash
mysql
}
main
EDIT
When I execute the first command without -t flag.
I have this: 
And it stays like this.
t.bash -c mysql