Im having some trouble filling my DB when installing a kar on karaf (Im using liquibase).
Im using windows 10, but using linux containers in docker, karaf 4.2.1 and mysql 5.7
There are the steps I did:
1-Went to task manager and stoped the mysql service.
2-Created and run a mysql 5.7 container doing the following:
docker run --name mysql-container -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7
Connected using 127.0.0.1 root/root in heidiSql and created the required DB's so when installing the kar liquibase will fill them with data.
3-Copied the kar to the repo folder in my karaf folder, added the folder to .tar, and then to gzip (.tar.gzip)
4-Created my karaf container using:
.\build.sh --from-local-dist --archive apache-karaf-with-kar.tar.gz
5-Did run karaf in the background:
docker run -d -p 127.0.0.1:8101:8101 --name=karaf-container karaf
Now I used putty and ssh to connect to karaf - localhost:8101. enter the user karaf and pass karaf.
All ok, I do the kar:install command, kar install but the bundles are in grace period.
I go to heidiSql and see that the DB's are not filled with data.
I go back to karaf connection, do a feature:refresh and i get erros like:
Error resolving artifact org.ops4j.pax.transx:pax-transx-features:xml:features:0.3.0: [Could not transfer artifact org.ops4j.pax.transx:pax-transx-features:xml:features:0.3.0 from/to central (http://repo1.maven.org/maven2/): Failed to transfer file: http://repo1.maven.org/maven2/org/ops4j/pax/transx/pax-transx-features/0.3.0/pax-transx-features-0.3.0-features.xml. Return code is: 501 , ReasonPhrase:HTTPS Required.]
I suposse the problem here is that somehow my connection to mysql doesn't work.
After some time the ssh connection is lost (I suposse this is normal if I dont do anything for some time there).
I tried to create a mysql-server container instead, but that way im not even able to connect using heidiSql.
Adicional question:
1-Where do I find the link to the kubernetes dashboard? I cant find it on docker.
2-I was having a first error when trying to docker run karaf:
\"karaf\": executable file not found in $PATH": unknown.
I resolved that because I realised that my karaf folder had less files than a downloaded binary one.
Basically the files are the files you see when you open the folder, the build.md, license, etc...
So I did copy paste to my folder of those files and I was able to run it. Im asking, because its still a mystery to me...
Thanks for your attention
edit: tried stoping the mysql-container and started mysql from the task manager and its the same, now im sure that for some reason its not connecting to the DB's. so I guess the problem is when I create a karaf container, maybe im missing some configurations. gonna keep trying
After 2 days I finally found the problem.
First, let me say that I did try too to create a network
docker network create mynet
and used the tag docker run --network=mynet in both mysql-container and karaf-container.
In my hook, I did try to replace localhost with mysql-container:3306 and even after that it didn't work.
Anyway, to resolve, I did what I said above, plus create a new super user:
docker exec -it mysql-container mysql -u root -p
CREATE USER 'user'#'localhost' IDENTIFIED BY 'pass';
GRANT ALL PRIVILEGES ON *.* TO 'user'#'%';
FLUSH PRIVILEGES;
And after that, all worked fine.
I will leave here a usefull link that was kinda hard to find but it has pretty good info:
https://codebeamer.com/cb/wiki/5854748
plus, for the 2 extra questions I asked:
1- Still didnt find the kube dashboard, didn't look much for it yet to be honest.
2- For what I have seen in the build.sh it will search a specific folder name 'apache-karaf', so I think this error here happens if you rename your folder and it doesnt match with the build.sh.
Related
I have a docker container running MySQL and another docker container running phpmyadmin. Both containers are running on my Ubuntu server.
Normally I can log into MySQL without problems thru phpmyadmin. However, this has happened several times in the past, that phpmyadmin runs into some issue and says:
"Cannot log in to the MySQL server" and
"mysqli::real_connect(): (HY000/2002): No such file or directory".
The funny thing is this happens at seemingly random times before giving this error. One time it worked for 4 months before giving this error message, another time it was 1 month, another time it was 3 months. There didn't seem to be any periodic or specific amount of time before it gave me this error.
I also checked the mysql container and it's still up and running and when I log into it (mysql container), I can access my db and see all the data and tables in it.
When I start the phpmyadmin container, I use this command. There is no config.user.inc.php file in /etc/phpmyadmin and it works for a few months.
docker run --name myadmin -d --link mysql_db_server:db -p 8080:80 phpmyadmin
I found some stackoverflow questions that were similar to my issue but doing what is suggested doesn't work.
One person said to edit the config.user.inc.php file and change the host to 127.0.0.1. I used the config.sample.php as my template for config.user.inc.php. In my config.user.inc.php file, I added
$cfg['Servers'][$i]['host'] = '127.0.0.1';
I then mounted a volume on my local linux server to map to /etc/phpmyadmin on the container such that when we started the container, it would use the config file. I ran:
docker run --name myadmin -d --link mysql_db_server:db -p 8080:80 -v /local/dir/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php phpmyadmin
However, this is worse than when I run the docker command without the volume because using the config.user.inc.php file makes me run into the error immediately. It's almost if the config.sample.inc.php file was misconfigured
The work around for me is to wait for phpmyadmin to give me the error, stop and kill the phpmyadmin container, then start a new one. However, if I can get it to work right off the bat and not run into this error, that would be most ideal.
Greetings and thanks in advance, I'm actually new to docker and docker-compose, watching a lot of videos and reading a lot of articles so far along with trying things.
I've got a front end container and a back end container that build and run alone as a Dockerfile and in a docker-compose setup.
(I've been building with Dockerfile first and then integrating the containers into docker-compose to make sure i understand things correctly)
I'm at the point where i need my database info, since i'll use docker-compose, as i understand it, it should build under the same network with a react front end and django back end.
I have a backup mysql dump file that I'm working with, what i think i need to do is have a container running mysql server and serving out my tables (like I have it locally working). I haven't been able to figure out how to import the backup into my docker mysql container.
Any help is appreciated.
What I've tried so far is using docker in the command line to outline the pieces i'll need in the Dockerfile and then what to move into the docker-compose as mentioned above:
docker run -d --name root -e MYSQL_ROOT_PASSWORD=root mysql # to create my db container
Then I've tried a bunch of commands and permutations of commands, recently in the CLI, here are some of my most recent trials and errors:
docker exec -i root mysql -uroot -proot --force < /Users/homeImac/Downloads/dump-dev-2020-11-10-22-43-06.dmp
ERROR 1046 (3D000) at line 22: No database selected
docker exec -i f803170ce38b sh -c 'exec mysql -uroot -p"root"' < /Users/homeImac/Downloads/dump-dev-2020-11-10-22-43-06.dmp
ERROR 1046 (3D000) at line 22: No database selected
docker exec -i f803170ce38b sh -c 'exec mysql -uroot -h 192.168.1.51 -p"root"' < /Users/homeImac/Downloads/dump-dev-2020-11-10-22-43-06.dmp
ERROR 1045 (28000): Access denied for user 'root'#'homeimac' (using password: YES)
I've scoured the web so far and i'm not sure where to go next, have I got the right idea? If anyone has an example of how to import a database dump (in dmp or dmp.gz), once i get that working, I'll actually do that in the docker-compose file.
Thinking about it, i just have to create the container and import so I might not even need a Dockerfile.
I'll cross that bridge when i get there. This is what I'm thinking though:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: 'app'
etc etc
I've learned a lot super fast, maybe too fast. Thanks for any tips!
The answer to your question is given in the docker hub page of MySQL.
Initializing a fresh instance
When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint->initdb.d. Files will be executed in alphabetical order. You can easily populate your mysql services by mounting a SQL dump into that directory and provide custom images with contributed data. SQL files will be imported by default to the database specified by the MYSQL_DATABASE variable.
In your docker-compose.yml use:
volumes:
- ${PWD}/config/start.sql:/docker-entrypoint-initdb.d/start.sql
and that's it.
Here's the answer that worked for me after working with 2 colleagues that know backend better where I work.
It was pretty simple actually. I created a directory in my repo that would be empty.
I added *.sql and *.dmp to my .gitignore so the dump files would not increase the size of my image.
That directory using docker-compose would be used as a volume under the mysql service:
volumes:
- ~/workspace/app:/workspace/app
The dump file is placed there and is imported into the sql service when I run:
mysql -u app -papp app < /path/to/the/dumpfile
I can go in using docker exec and verify not only the database is there but the tables from my dump file are there as well.
For me, I had to create a new superuser also in my backend container through our Django app.
python3 manage.py createsuperuser
With that, then logging in on localhost:8000/api, everything was linked up between the mysql, backend, and frontend containers.
Hope this helps! I'm sure not all the details are the same for others post volumes, but using volumes, I didn't have to copy any dump file in and it ended up automatically imported and served. That was my big issue.
another way:
docker exec -i containername mysql -uroot -ppassword mysql < dump.sql
from the folder where dump.sql resides
I need your help again.
Is there a way to reset all configuration in MySQL?
Here's what happened. I previously have a project installed and this time I'm setting up a new one.
In this new project, I wanted to set it up with my a new database, new username I created and password. However, when I reached the point where I had to execute php artisan migrate, it keeps throwing me an error saying PDOException::("SQLSTATE[HY000] [2002] No such file or directory")
If not that error, it's throwing connection refused instead.
Note: I'm using laradock.
Now, I'm at the point where I'd just rather reset the whole MySQL because I'm thinking it's conflicting with my previous configuration with my previous project.
As I searched online, I've tried the following:
1. Restarted server
2. Changed db_host from 127.0.0.1 to localhost and vice-versa
3. Added the project's directory to the dev environment setting
4. Docker-compose down and then up again
5. Even uninstalled and reinstalled docker itself
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=newdbname
DB_USERNAME=newusername
DB_PASSWORD=newpassword!
All I want is to be able to execute php artisan migrate using the new credentials I set.
If you really do not need any old data in database, you can just delete them & reset up a container:
# stop mysql service
docker-compose stop mysql
# delete old mysql database
rm -rf ~/.laradock/data/mysql
# resetup mysql container
docker-compose up -d nginx mysql
You can get the mysql database location according to docker-compose.yml & env-example:
docker-compose.yml:
volumes:
- ${DATA_PATH_HOST}/mysql:/var/lib/mysql
env-example:
DATA_PATH_HOST=~/.laradock/data
I have installed docker on my mac. I have MySQL container which is running on my local machine (MAC).
Docker ps command is giving me below output -
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b5c50b2d334a test_mysql2 "docker-entrypoint.s…" 2 hours ago Up 2 hours (healthy) 0.0.0.0:32783->3306/tcp test_mysql2_1
I know username and password to the mysql which would be setup up in the container.
I want to connect to mysql and run some queries But I am not able to figure out how to connect to it. Any help will be appreciated.
Do you want to Connect to MySQL through Docker if yes; Kindly follow this step by step procedure that I am using.
Step 1 : Pull MySql image from docker hub. The following command will pull the latest mysql image.
cli> docker pull mysql
Step 2: Run a container from this image. ‘-name’ gives a name to the container. ‘ -e’ specifies run time variables you need to set. Set the password for the MySQL root user using ‘MYSQL_ROOT_PASSWORD’. ‘-d’ tells the docker to run the container in background.
cli> docker run --name=testsql -e MYSQL_ROOT_PASSWORD=rukshani -d mysql
This will output a container id; which means that the container is running in the background properly.
Step 3: Then check the status of the container by issuing, ‘docker ps’ command
cli> docker ps
Now you should be able to see that MySQL is running on port 3306.
Step 4: To checkout the logs of the running container use the following command
cli > docker logs testsql
Step 5: Find the IP of the container using following. Check out the “IPAddress” from the output, this will tell you the IP address.
cli> docker inspect testsql
Now you should be able to connect to MySQL using tIPs ip address on port 3306.
Base on what I understand from your question, this is what you need. (I hope so)
(This is not my own documentation, I only like to document everything most especially those procedure that I cannot put in my head, so that if ever the same thing happen or I need same procedure in the future, I will not waste my time to research again, but instead I will open my notes and run the commands.)
As you can see in the output of docker ps, the port 32783 (local machine) is mapped to the port 3306 inside the docker container. If you are using a MySQL Client (e.g. MySQL Workbench) you should be able to connect using ip localhost and port 32783. If not, you should go with docker exec and then open a interactive mysql shell inside the container (As mulg0r commented).
I'm trying to use MySQL docker container in my host system to make installation and configuration processes much easier and faster.
So, I've pulled an image from:
https://hub.docker.com/r/mysql/mysql-server/
Then started container based on this image..
Container started fine, but I was not able to connect to this DB from my host system (everything is ok if I try to connect from container). It failed with a message:
ERROR 1130 (HY000): Host '<here goes my IP>' is not allowed to connect to this MySQL server
So, as I understand, my root user has no enough permissions.
I've entered my container:
docker exec -it mysql bash
Connected to DB:
mysql -uroot -ppassword
Updated permissions for my root user:
use mysql;
UPDATE user SET Host="%" WHERE User='root';
It's updated fine.
Than I decided to save my updated image somehow... I've found this guide:
http://docs.oracle.com/cd/E52668_01/E75728/html/section_c5q_n2z_fp.html
After executing:
docker stop mysql
docker commit -m "Fixed permissions for root user" -a "Few words about author" `docker ps -l -q` myrepo/mysql:v1
docker rm mysql
docker run --name new-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=pass -d myrepo/mysql:v1
I've found that my root user hasn't permissions again.
What is wrong here?
How to public my updated image into my Dockerhub?
My original answer is for persisting the change in the MySQL data after it has been initialized. But since you want to do this in the image for every initialization automatically there is a different approach for this. You can use one of the following options:
There is an environment variable called MYSQL_ROOT_HOST for this image where you can set the host (https://github.com/mysql/mysql-docker/blob/mysql-server/5.7/docker-entrypoint.sh#L63-L69). You should be able to set this to % to allow all hosts to connect as root such as -e MYSQL_ROOT_HOST="%".
The image supports adding SQL files to /docker-entrypoint-initdb.d/ to be initialized on startup (https://github.com/mysql/mysql-docker/blob/mysql-server/5.7/docker-entrypoint.sh#L98-L105). You can create your SQL file that has UPDATE mysql.user SET Host="%" WHERE User='root'; in it and then ADD that file to /docker-entrypoint-initdb.d/ in your own image. Then, when starting a container based on that image it will initialize that SQL file.
That image specifies a default volume to hold the MySQL data at https://github.com/mysql/mysql-docker/blob/mysql-server/5.7/Dockerfile#L11. When you start the container, a volume is created for that container. When you update the permissions for the root user, it is saved in this volume (it is actually part of MySQL data for the mysql database). But once you remove the container, that volume is also lost.
There are usually two things you can do in this case to preserve the data between container restarts or even new containers:
Create a named volume and mount the data there. To do this you can run docker volume create mysqldata. Then, when starting the container mount the data with -v mysqldata:/var/lib/mysql. This volume will persist even after you stop or delete your MySQL container.
Bind mount the data to a host folder. Instead of creating a volume, you can just mount a folder such as -v /mnt/mysqldata:/var/lib/mysql. This will persist all your MySQL data on the host at /mnt/mysqldata.
Though, these are not the only ways to persist data, they are two built-in methods. There are also Docker volume plugins that allow you to use other storage mediums (examples might be https://github.com/rancher/convoy for NFS and https://github.com/NetApp/netappdvp for NetApp).
docker exec -it mysql bash
chown -R mysql:mysql /var/lib/mysql
if you change permission of volume in host, above code will correct permission denied for root.