Docker-compose problem copying MySQL config in CircleCI - mysql

The following works fine on a local machine, but fails when checked into CircleCI:
mysql:
image: mysql:5.7
ports:
- 3306:3306
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=true
- MYSQL_ROOT_HOST=%
restart: always
volumes:
- ./docker/mysql/mysqld.cnf:/etc/mysql/conf.d/mysql.cnf
There is a file at ./docker/mysql/mysqld.cnf under the checked out project.
The error shown on CircleCi is:
ERROR: for proj-server_mysql_1 Cannot start service mysql: b'oci
runtime error: container_linux.go:265: starting container process
caused "process_linux.go:368: container init caused
\"rootfs_linux.go:57: mounting
\\\"/home/circleci/max/proj-server/docker/mysql/mysqld.cnf\\\"
to rootfs
\\\"/var/lib/docker/aufs/mnt/4a9af90d342b491ae92af5a88360d2e34fce0d21c15f8a648767e89fb51aa\\\"
at
\\\"/var/lib/docker/aufs/mnt/4a9af90d342b491ae92af5a88360d2e34fce0d21c15f8a648767e89fb51aa/etc/mysql/conf.d/mysql.cnf\\\"
caused \\\"not a directory\\\"\""\n: Are you trying to mount a
directory onto a file (or vice-versa)? Check if the specified host
path exists and is the expected type'

It's not possible to use volume mounting with the docker executor, but with using the machine executor it's possible to mount local directories to your running Docker containers. You can learn more about the machine executor here on our docs page.
https://support.circleci.com/hc/en-us/articles/360007324514-How-can-I-mount-volumes-to-docker-containers-

Related

how to make my database accessible to my docker container?

I have a docker container which is based on a springboot project and generated with this command :
docker run --net=host -d --restart unless-stopped -v /home/ramses/dockerTest:/uploads/deployment --name ramses-bl2 abyster01/ramses-bl2:528
but the container does not access to my database, as you can see in this error :
Caused by: org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: 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.
My container is launched in host mod, and i verified the root (the user i set in my springboot project properties) is set as user in my database as you can see in this screenshots :
Finally i test connection to my database successfully with the same credentials as in my properties.
But i don't know why i'm getting this error.
For what you need it is not necessary to run in host mode. In general you should always avoid doing so.
First of all check the IP address of the host on your local network (not the local interface 127.0.0.1 but something like 192.168.X.X or similar).
Make sure you can access your database from host by connecting to this IP and the correct port. Also check that the user you use can connect also from hosts other than localhost.
Then run the container with the additional flag: --add-host mydatabase:192.168.X.X. Your application inside the container should use mydatabase as the database server name.
I would recommend for you to use a docker-compose.yml file. Add to the file the following:
version: '3'
services:
mysql-standalone:
image: mysql:latest
environment:
- MYSQL_ROOT_PASSWORD=***
- MYSQL_DATABASE=***
- MYSQL_USER=***
- MYSQL_PASSWORD=**
volumes:
- data:/var/lib/mysql
spring-boot:
image: *your-app-name-image*
ports:
[8080:8080]
build:
context: ./
dockerfile: Dockerfile
depends_on:
- mysql-standalone
volumes:
data:
Then in the application.properties have the following configuration
server.port=8080
spring.datasource.url=jdbc:mysql://<container-name>:3306/<db-name>
spring.datasource.username=***
spring.datasource.password=***
Finally, run docker-compose up.
Note that one of the differences between docker run versus docker-compose is that docker-compose reads configuration data from a YAML file instead of having to set your configuration from a cli

Error while running docker compose up while connecting to sql database

I have setup docker environment in my local machine to run our development code by pointing to dev mysql database url. Done all configurations and was able to build the docker using docker-compose build command. Even though i was able to build it successfully , on running the command docker-compose up , i am getting numerous errors.
Few of the errors are :
ERROR - TransactionManager Failed to start new registry transaction.
ERROR- AsyncIndexer. Error while indexing
I saw another answers in stackoverflow and updated my code accordingly like limiting max active connections to field to 50 in master-datasources.xml file and changing the configuration url to the below format.
jdbc:mysql://${db_url}:${db_port}/${carbon_db}?autoReconnect=true&relaxAutoCommit=true
Docker version : 19.03.5
Docker compose version : 1.24.1
My docker-compose.yml file:
services:
wso2am:
build: ./apim
image: wso2am:2.1.0
env_file:
- sample.env
ports:
- "9444:9444"
- "8281:8281"
- "8244:8244"
depends_on:
- wso2is-km
wso2is-km:
build: ./is-as-km
image: wso2is-km:5.3.0
env_file:
- sample.env
ports:
- "9443:9443"
My sample.env file:
HOST_NAME=<hostname>
DB_URL=<db_connection_url>
DB_USER=admin
DB_PASS=adminpassword
DB_PORT=3306
CARBON_DB=carbondb
APIM_DB=apimdb
ADMIN_PASS=<wso2_password>
Can anyone provide a solution for this issue.

How to access redmine log folder inside a docker after a docker-compose?

I am a noob with docker, and I try to implement a redmine+mysql container in Windows environment and add production mysql dump in it after that.
I have an issue when trying to access to redmine after my execution of sql script production dump, after sql launch I only have Internal error when browsing redmine with docker.
I don't know how to change the database name in the data-compose file , if I replace 'redmine' with anything else my script is broken.
Also I don't know how I can access to redmine error logs folder in my docker to fix the issue.
Here is my docker-compose file :
version: '3.7'
services:
db:
image: mysql:5.5.47
restart: always
ports:
- 3306:3306
volumes:
- .\mysql_files\data-mysql:/var/lib/mysql
- .\mysql_files\backup-mysql:/var/lib/mysql/backup
- .\mysql_files\dump-mysql:/docker-entrypoint-initdb.d
environment:
MYSQL_ROOT_PASSWORD: monmdp
MYSQL_DATABASE: redmine
redmine:
image: redmine:4.0.3
restart: always
ports:
- 8080:3000
depends_on:
- db
volumes:
- .\redmine_files\files:/usr/local/redmine/files
- .\redmine_files\logs:/var/log/redmine
environment:
REDMINE_DB_MYSQL: db
REDMINE_DB_PASSWORD: monmdp
as you can see I tried to access to redmine log folder in this line :
- .\redmine_files\logs:/var/log/redmine
but the folder is still empty :(
expected result : can browse redmine with production data dump
current result : Can't browse redmine and can't access log folder to check what's wrong.
Thanks for your help
From what I understand, you are trying to access the logs of redmine container but you found the .\redmine_files\logs directory empty. First, you need to check whether there are logs in the docker /var/log/redmine directory or not. You can do so by running commands in redmine shell itself. Use the command docker exec -it redmine /bin/bash to move to redmine shell and cd to /var/log/redmine to check if the logs are present there or not. If you don't find the logs there then that means that there was not logs to be replicated to ./redmine_files/logs.
If you find the logs in /var/log/redmine then there must be some issue with your docker-compose file, but it seems fine to me. Also, as #Mihai has suggested you can check the logs of redmine using the command sudo docker-compose logs redmine to see if it is running properly or not.
this docked image host redmine under /usr/src/redmine/ so you should use
- .\redmine_files\logs:/usr/src/redmine/log

Docker on Windows Data Persistence - Host Mapping vs Data Volume

I'm very new to Docker and after reading about data volumes I'm still somewhat confused by the behaviour I'm seeing.
In my compose file I had an entry for mysql like this:
db:
image: mysql
restart: always
volumes:
- ./database:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: p4ssw0rd!
networks:
- back
This mapped the /database directory to /var/lib/mysql. The database files where created and I could start Wordpress, install, add a post. The problem as it never persisted any created data. If I restarted Docker and executed:
docker-compose up -d
The database was empty.
Changing this to:
db:
image: mysql
restart: always
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: p4ssw0rd!
networks:
- back
And adding in a volume like this:
volumes:
db_data:
Now persists the data in the Docker data volume and restarting works. Any data created during the last run is still present.
How would I get this to work using the host mapped directory?
Am I right in thinking the second example using volumes is the way to go?
Docker volumes on windows work a bit different way than Linux. Basically on Windows, docker runs a VM and the docker is setup inside the VM. So it seems to you that you run docker commands locally on Windows but the actual stuff happens in background inside a VM.
docker run -v d:/data:/data alpine ls /data
First you need to make share the D: in docker settings. You can find a detailed article explaining the steps for doing so
https://rominirani.com/docker-on-windows-mounting-host-directories-d96f3f056a2c

In jenkins, docker-compose mysql 0mERROR 1396 (HY000) at line 1: Operation CREATE USER failed for 'root'#'%'

I have a docker-compose.yml that sets up an API service, a test MYSQL database, and a java task worker app. I then run API integration tests against the local stack. Each time I run it, I execute docker-compose rm -v to ensure that my DB is the same for each test run.
Locally, my docker-compose file sets up my images properly.
In Jenkins, using the same docker-compose file, I get the above error, copied here:
0mERROR 1396 (HY000) at line 1: Operation CREATE USER failed for 'root'#'%'
It appears something might be going on with the hostname of the image.
Here's the Dockerfile for my DB setup:
FROM mysql
ENV MYSQL_DATABASE="db_name"
ENV MYSQL_USER="user"
ENV MYSQL_PASSWORD="password1"
ENV MYSQL_ROOT_PASSWORD="password"
COPY *.sql /docker-entrypoint-initdb.d/
EXPOSE 3306
Here's my docker-compose.yml:
web-api:
image: registry/api-repo
links:
- test-db
ports:
- "8625:8625"
environment:
- MYSQL_DATABASE=db_name
- MYSQL_HOST=test-db
- MYSQL_USER=user
- MYSQL_PASSWORD=password1
custodial-java:
image: registry/java-repo
links:
- test-db
environment:
- MYSQL_DATABASE=db_name
- MYSQL_HOST=test-db
- MYSQL_USER=user
- MYSQL_PASSWORD=password1
test-db:
image: registry/test-db
ports:
- "3306:3306"
I am likely missing something in my Jenkins config, but I'm not sure where to look.
As it turned out, the version of Docker on Jenkins was not the same as my local machine. On my local machine, i was using Docker 17.03, whereas the Jenkins box was running Docker Toolbox 1.5.
After updating the build machine to use the latest docker toolbox (1.12 i believe), I no longer get this error and my automation test functions!