Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do I connect a Confluence container to a MySQL container?

Brad Ellis May 3, 2019

Hi Folks!

I'm trying to install confluence, using mysql in a docker containerized environment.
I've never installed confluence before and I'm still quite green when it comes to building with docker.

Host OS is Ubuntu 18.04.02. All versions of software are latest as of this writing.

So far I have the following images:
atlassian/confluence-server
mysql

I know I need to add the JDBC driver to confluence to use the database, so I've set up a Dockerfile so I can build a custom image:

FROM atlassian/confluence-server
COPY mysql-connector-java-5.1.47.jar /opt/atlassian/confluence/confluence/WEB-INF/lib

I can successfully create the new image and have verified that the connector is in the right place when I run a container from it.

Now I'm trying to write a docker-compose.yml to start these, get them connected and make sure they're always on. This I am VERY unsure about. I think it should work but I'm writing this question, aren't I? :)

Please trust that I have whitespacing correct - I can't seem to paste this into a codeblock.

version: '3'
services:
confl-mysql:
image: mysql
restart: always
networks:
- confluencenet
volumes:
- /data/mysql:/var/lib/mysql
environment:
- MYSQL_RANDOM_ROOT_PASSWORD=yes
- MYSQL_DATABASE=confluence
- MYSQL_USER=confluence
- MYSQL_PASSWORD=confluence
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]

confluence:
image: confluence-mysql-driver
restart: always
networks:
- confluencenet
volumes:
- /data/confluence:/var/atlassian/application-data/confluence
- /data/mysql:/var/lib/mysql
ports:
- 8090:8090
- 8091:8091

networks:
confluencenet: {}

Both containers start when I perform 'docker-compose up' and I can hit the confluence page, but when it comes time to set up the database I can't for the life of me figure out how to connect to the mysql.

image.png

I've tried with 'localhost', 'mysql', the container name 'confl-mysql_1' all with no success:

Can't reach database server or port
SQLState - 08S01

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

 I'd greatly appreciate any support or guidance to help get this working!

 

Thanks!

1 answer

1 accepted

1 vote
Answer accepted
Brad Ellis May 3, 2019

I figured this out myself!

First, for the hostname, I wasn't quite using the right pod name. 

docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
627be820baef confluence-mysql-driver "/tini -- /entrypoin…" 17 minutes ago Up 54 seconds 0.0.0.0:8090-8091->8090-8091/tcp confluence_confluence_1
fa813e5e48cd mysql/mysql-server:5.7 "/entrypoint.sh mysq…" 17 minutes ago Up 55 seconds (healthy) 3306/tcp, 33060/tcp confluence_confl-mysql_1

I should have been using confluence_confl-mysql_1 for jdbc:mysql://confluence_confl-mysql_1/confluence

Additionally, I had the wrong version of MySQL. In the compose file, the image I wanted was actually mysql/mysql-server:5.7

Finally, I didn't need to mount the mysql database directory in the confluence container. Instead it just uses networking to connect.

My final docker-compose.yml file is:

version: '3'
services:
confl-mysql:
image: mysql/mysql-server:5.7
restart: always
networks:
- confluencenet
volumes:
- /data/mysql:/var/lib/mysql
environment:
- MYSQL_RANDOM_ROOT_PASSWORD=yes
- MYSQL_DATABASE=confluence
- MYSQL_USER=confluence
- MYSQL_PASSWORD=confluence
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]

confluence:
image: confluence-mysql-driver
restart: always
networks:
- confluencenet
volumes:
- /data/confluence:/var/atlassian/application-data/confluence
ports:
- 8090:8090
- 8091:8091

networks:
confluencenet: {}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events