How to create docker-compose for JIRA and MySQL - mysql

I'm trying to create a docker-compose.yml file that will bring up JIRA and MySQL. Here's my file:
version: '3'
services:
jira:
depends_on:
- mysql
container_name: jira
restart: always
networks:
- jiranet
build:
context: .
dockerfile: Dockerfile.jira
environment:
- ATL_DB_TYPE=mysql
- ATL_DB_DRIVER=com.mysql.cj.jdbc.Driver
- ATL_JDBC_URL=jdbc:mysql://mysql:3306/jiradb
- ATL_JDBC_USER=jira
- ATL_JDBC_PASSWORD=jellyfish
ports:
- 8080:8080
volumes:
- jira-data:/var/atlassian-data/jira
mysql:
container_name: mysql
restart: always
image: mysql:5.7
networks:
- jiranet
environment:
- MYSQL_ROOT_PASSWORD=ChangeMe!
- MYSQL_DATABASE=jiradb
- MYSQL_USER=jira
- MYSQL_PASSWORD=jellyfish
command: [mysqld, --character-set-server=utf8, --collation-server=utf8_bin, --default-storage-engine=INNODB, --max_allowed_packet=256M, --innodb_log_file_size=2GB, --transaction-isolation=READ-COMMITTED, --binlog_format=row]
volumes:
- mysql-data:/var/lib/mysql
networks:
jiranet: {}
volumes:
jira-data:
mysql-data:
Unfortunately, I'm getting JIRA startup errors when it tried to initialize the database, of the form:
CREATE command denied to user 'jira'#'172.22.0.3' for table 'jiraaction'
I'm guessing it's because the mysql container is creating user jira, but only allowing it to connect from localhost. But, the JIRA container is being seen as coming from an an external IP.
Any ideas on how I can get the jiradb database in mysql to be accessible by the JIRA container by user jira?

I figured out the problem -- I was missing an environment variable in the jira container:
ATL_DB_SCHEMA_NAME=jiradb
After that, things worked fine!

Related

My mysql container in Docker, via the feature I gave it from the dockerfile to restart itself, keeps turning itself on and off

My mysql container in docker, via the feature I gave it from the dockerfile to restart itself, keeps turning itself on and off after I attempted the docker-compose up --build command.
My Dockerfile contains several containers, including an apache, a mysql with a volume to save the data of a database and a php.
I ran into this problem as I was carrying out various tests since I had just created the volume and I wanted to see if the database was not losing the data inside it.
After various commands of docker-compose down and docker-compose up it happened that the mysql container did not work anymore, not even after other commands docker-compose down and docker-compose build --no-cache.
below i added my docker.compose.yml
all versions of the images and data for the database are taken from the various dockerfiles
version: "3.2"
services:
php:
build:
context: './php/'
args:
PHP_VERSION: ${PHP_VERSION}
networks:
- backend
volumes:
- ${PROJECT_ROOT}/:/var/www/html/
container_name: php
apache:
build:
context: './apache/'
args:
APACHE_VERSION: ${APACHE_VERSION}
depends_on:
- php
- mysql
networks:
- frontend
- backend
ports:
- "80:80"
volumes:
- ${PROJECT_ROOT}/:/var/www/html/
container_name: apache
mysql:
image: mysql:${MYSQL_VERSION:-latest}
restart: always
ports:
- "3306:3306"
volumes:
- data:/var/lib/mysql
networks:
- backend
environment:
MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
MYSQL_DATABASE: "${DB_NAME}"
MYSQL_USER: "${DB_USERNAME}"
MYSQL_PASSWORD: "${DB_PASSWORD}"
container_name: mysql networks:
frontend:
backend:
volumes:
data:
Anyone can describe me what I can do in this case in order not to lose the progress made so far within the database since doing a little research they tell me that the volume and the image of mysql may have been corrupted?

Docker Compose - Can't access Database

My Docker Wordpress Container some how cannot connect to my database container. I tried to pass the credentials through the environment key.
I'm using external volumes that stores the Data from my previous Wordpress build as well as the data from the Database.
docker-compose.yml
version: '3'
services:
db:
image: mysql:5.7
container_name: db
restart: unless-stopped
env_file: .env
environment:
- MYSQL_DATABASE=wordpress_oxygen
volumes:
- wordpress_db-data:/var/lib/mysql
networks:
- conturas-network
wordpress:
depends_on:
- db
image: wordpress:5.6.0-fpm-alpine
container_name: wordpress
restart: unless-stopped
env_file: .env
environment:
- WORDPRESS_DB_HOST=db:3306
- WORDPRESS_DB_USER=$MYSQL_USER
- WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
- WORDPRESS_DB_NAME=wordpress_oxygen
volumes:
- wordpress_data:/var/www/html
networks:
- conturas-network
webserver:
depends_on:
- wordpress
image: nginx:1.19.6-alpine
container_name: webserver
restart: unless-stopped
ports:
- "80:80"
volumes:
- wordpress_data:/var/www/html
- ./nginx-conf:/etc/nginx/conf.d
- certbot-etc:/etc/letsencrypt
networks:
- conturas-network
certbot:
depends_on:
- webserver
image: certbot/certbot
container_name: certbot
volumes:
- certbot-etc:/etc/letsencrypt
- wordpress_data:/var/www/html
command: certonly --webroot --webroot-path=/var/www/html --email username#xyz.io --agree-tos --no-eff-email --force-renewal -d xyz.io -d www.xyz.io
volumes:
certbot-etc:
wordpress_data:
external: true
wordpress_db-data:
external: true
networks:
conturas-network:
driver: bridge
Error Logs from the db-container
...
2020-12-27T15:53:26.593191Z 2 [Note] Access denied for user 'wordpress_oxygen'#'172.30.0.3' (using password: YES)
Thanks for helping!
The very last line of the logs give the important hint on the underlying issue:
[Note] Access denied for user 'wordpress_oxygen'#'172.30.0.3' (using password: YES)
It means that the database credentials used to connect to the database are incorrect - i.e. the username/password combination.
But since this is logged by the database it means WordPress is actually able to connect to the database - i.e. your docker networks are setup correctly.
You should verify now that the values of configured credentials (WORDPRESS_DB_USER, WORDPRESS_DB_PASSWORD etc.) are actually correct - which is the same as MYSQL_USER and MYSQL_PASSWORD used at the time of initializing the database - that is, the environment variables MYSQL_USER, MYSQL_PASSWORD etc. are only used when the database volume is empty and needs to be initialized, see Environment Variables in the image description:
Do note that none of the variables below will have any effect if you start the container with a data directory that already contains a database: any pre-existing database will always be left untouched on container startup.
You may also try to re-initialize the database by deleting the volume and starting a fresh instance of the service.
Also note that environment and env_file two different ways of specifying environment variables for the service, but mixing those two is bad practice since it can lead to unexpected behavior.
If you want to import values from your .env file to use for variable substitution you don't need to "import" it with env_file since it is loaded automatically for docker-compose! I.e. your current configuration does not do what you probably think it does.
What I did to fix the issue
I removed the the environment keys from the whole compose file.
Why did I do this?
I realized with the help of #acran answers, that the volume that I passed into the docker-compose file, was already a ready to use copy of my Initial Wordpress build/installation the same goes for the MySQL Database. (This means all credentials was already stored inside of each volume) Because of that I was not able to pass environment-variables to the composition, to be more precise, you can pass environment-variables to a build but they would simple have no effect on the finished container build.
You can only set environment-variables at the initial build.
Result
version: '3.3'
services:
db:
image: mysql:5.7
container_name: db
restart: unless-stopped
volumes:
- wordpress_db-data:/var/lib/mysql
networks:
- my-network
wordpress:
depends_on:
- db
image: wordpress:5.6.0-fpm-alpine
container_name: wordpress
restart: unless-stopped
volumes:
- wordpress_data:/var/www/html
networks:
- my-network
webserver:
depends_on:
- wordpress
image: nginx:1.19.6-alpine
container_name: webserver
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- wordpress_data:/var/www/html
- ./nginx-conf:/etc/nginx/conf.d
- certbot-etc:/etc/letsencrypt
networks:
- my-network
certbot:
depends_on:
- webserver
image: certbot/certbot
container_name: certbot
volumes:
- certbot-etc:/etc/letsencrypt
- wordpress_data:/var/www/html
command: certonly --webroot --webroot-path=/var/www/html --email my.name#xyz.io --agree-tos --no-eff-email --expand --noninteractive -d xyz.io -d www.xyz.io -d dev.xyz.io
volumes:
certbot-etc:
wordpress_data:
external: true
wordpress_db-data:
external: true
networks:
my-network:
driver: bridge

Prisma 2 docker container can't connect MySQL Database container

I'm developing Backend server with prisma 2, MySQL, Docker-compose, GraphQL-Yoga server
My OS is Windows 10, docker compose use debian-openssl-1.1.x
problem is prisma 2 container can't connect MySQL container
docker-compose.yml
version: "3.7"
services:
mysql:
image: mysql:8.0.19
container_name: mysql
ports:
- 3306:3306
restart: always
environment:
MYSQL_DATABASE: $${MYSQL_DATABASE}
MYSQL_ROOT_PASSWORD: $${MYSQL_ROOT_PASSWORD}
volumes:
- /var/lib/mysql
prisma:
links:
- mysql
depends_on:
- mysql
container_name: prisma
ports:
- "5555:5555"
build:
context: back/prisma
dockerfile: Dockerfile
environment:
MYSQL_URL: $${MYSQL_URL}
MYSQL_ROOT_PASSWORD: $${MYSQL_ROOT_PASSWORD}
volumes:
- /app/prisma
backend:
links:
- mysql
depends_on:
- mysql
container_name: backend
ports:
- "4000:4000"
build:
context: back
dockerfile: Dockerfile
environment:
MYSQL_URL: $${MYSQL_URL}
FRONTEND_URL: $${FRONTEND_URL}
volumes:
- ./back:/app
- ./back/node_modules:/app/node_modules
- ./back/prisma:/app/prisma
frontend:
container_name: frontend
ports:
- "3000:3000"
build:
context: front
dockerfile: Dockerfile
environment:
BACKEND_URL: $${BACKEND_URL}
volumes:
- ./front:/app
- ./front/node_modules:/app/node_modules
.env
MYSQL_URL="mysql://root:prisma#mysql:3306/prisma"
BACKEND_URL=http://localhost:4000
FRONTEND_URL=http://localhost:3000
MYSQL_DATABASE:"prisma"
MYSQL_ROOT_PASSWORD:"prisma"
-schema.prisma
generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "debian-openssl-1.1.x"]
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
.env in prisma folder
DATABASE_URL="mysql://root:prisma#mysql:3306/prisma"
when i run docker-compose (docker-compose up), prisma container (prisma 2 studio) show this logs
Error in Prisma Client request:
Error:
Invalid `prisma.user.count()` invocation:
Authentication failed against database server at `mysql`, the provided database credentials for `root` are not valid.
Please make sure to provide valid database credentials for the database server at `mysql`.
at PrismaClientFetcher.request (/root/.cache/prisma/studio/app/runtime/index.js:1:52273)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
enter image description here
I think this error occurred because MySQL container has a password different from MYSQL_ROOT_PASSWORD which I wrote in the doctor-compose.yml.
But, i think there seems to be no problem with the setup, why is this error happening?
And if i did not set up MYSQL_ROOT_PASSWORD, what is the default password value generated by MySQL container?
I searched for days to find the answer to this problem, but I could not get the answer. please give me some advices. thank you

Docker compose mysql exited with code 0

I'm trying to add mysql to a docker compose file, but every time it gives me the error some_name exited with code 0. I tried diffent configurations and even took the following config from the docker docs:
# Use root/example as user/password credentials
version: '3.1'
services:
db:
image: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: example
adminer:
image: adminer
restart: always
ports:
- 8080:8080
In this case adminer works but mysql doesn't.
My config:
mysqldb:
image: mysql
container_name: ${MYSQL_HOST}
env_file:
- ".env"
environment:
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
ports:
- "8989:3306"
Both my config and that from the docker docs keep giving me the same error. Although any other services are working fine. Any ideas?
How unfortunate. After hours I deleted my mysql image and after that everything worked fine.

Incorrect docker compose on phpmyadmin

According to the docker compose yaml,
version: '3'
services:
db:
image: mariadb:latest
container_name: mariadb
restart: always
volumes:
- ./mysql/initdb/:/docker-entrypoint-initdb.d
- ./mysql/data/:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=root-pwd
- MYSQL_DATABASE=appdb
- MYSQL_USER=appuser
- MYSQL_PASSWORD=user-pwd
php:
image: php:fpm-alpine
container_name: php
restart: always
volumes:
- ./www/:/var/www/html
expose:
- "9000"
nginx:
image: nginx:alpine
container_name: nginx
restart: always
volumes:
- ./nginx/conf/nginx.conf:/etc/nginx/conf/nginx.conf:ro
- ./nginx/conf.d:/etc/nginx/conf.d:ro
- ./www:/var/www/html
ports:
- "80:80"
pma:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
restart: always
ports:
- "8080:80"
it produces an error:
#2002 - php_network_getaddresses: getaddrinfo failed: Try again — The server is not responding (or the local server's socket is not correctly configured).
when logging in to phpMyadmin (http://127.0.0.1:8080).
I have tried to fix this problem, but nothing works.
Could you please find a solution?
Any recommendations/comments are welcomed here.
I had a similar problem try this in the links directive - container-name:db as below
links:
- mariadb:db
you should links your phpmyadmin to database services in order to use the db service
pma:
image: phpmyadmin/phpmyadmin
links:
- db
container_name: phpmyadmin
restart: always
ports:
- "8080:80"
environment:
- PMA_HOST: maria_db
here is more about docker compose services links
If you set the following environment variable in docker compose:
pma:
environment:
- PMA_ARBITRARY=1
then you will be given the opportunity to enter the host server manually on the login screen. Enter the name of the database service there. In your case the name of the service is db