Error while connecting guacamole to mysql - mysql

enter image description here
Error while connecting to the database
Facing the guacamole connectivity issue with the mysql database. Tried to install mysql inside guacamole container and the connection was established successfully, where as, when we trigger the same container from application, db connectivity is giving an issue.
Below is the docker file that has been used. Any leads will be super helpful
FROM guacamole/guacamole:1.3.0 as guacamole
FROM **(customCentos)centos7_linux:latest
RUN yum update -y &&
yum install -y java-1.8.0-openjdk
COPY --from=guacamole /usr/local/tomcat /usr/local/tomcat
COPY --from=guacamole /opt/guacamole /opt/guacamole
COPY logback.xml /opt/guacamole
COPY java.security /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64/jre/lib/security/java.security
WORKDIR /opt/guacamole
ENV PATH /usr/local/tomcat/bin:$PATH
CMD ["/bin/bash", "/opt/guacamole/bin/start.sh"]

Related

Error : The command '/bin/sh returned a non-zero code: 1

When I am trying to build one of my projects by running a script written by previous team in my ubuntu 16.04
sudo ./build
I am getting error :
Step 8/24 : RUN service mysql start
---> Running in 3djjk653642d
* Starting MySQL database server mysqld
...fail!
The command '/bin/sh -c service mysql start' returned a non-zero code: 1
My Dockerfile looks like:
COPY schema.sql /tmp/schema.sql
### User with ALL accesses (winter/toor)
RUN service mysql start
RUN mysql < /tmp/schema.sql
RUN mysql -e "CREATE USER 'winter'#'%' IDENTIFIED BY 'toor'"
RUN service mysql start && mysql -e "GRANT ALL ON its.* TO 'winter'#'%'"
Please ,any help ?
RUN statements in a Dockerfile are used to run a command which will have some effect on the filesystem, that is then saved in another layer.
It's not normal to start a service like this, as the state of the memory (where the service is running) is not stored in the image, it can only be running in a running container.
The normal way to do stuff like this would be to write a bash script, (called start.sh, or something similar), copy it into the image and then run from an ENTRYPOINT / CMD line at the end of the Dockerfile. This will be run when the container is created in a docker run ... command
start.sh:
service mysql start
mysql < /tmp/schema.sql
mysql -e "CREATE USER 'winter'#'%' IDENTIFIED BY 'toor'"
service mysql start && mysql -e "GRANT ALL ON its.* TO 'winter'#'%'"
Dockerfile:
COPY schema.sql /tmp/schema.sql
COPY start.sh /
ENTRYPOINT ["/start.sh"]
Have a read here for some information on the difference between ENTRYPOINT & CMD and when each should be used.
Better still - use the official MySQL image from Docker hub. Through the use of environment variables, you could probably achieve all you require.
For me the error was:
yum -y install nginx' returned a non-zero code: 1
This docker file helped me:
FROM centos:7
MAINTAINER linuxtechlab
LABEL Remarks="This is a dockerfile example for Centos system"
RUN yum -y update
RUN yum -y install httpd
RUN yum clean all
RUN yum -y install nginx
EXPOSE 80
#ENV HOME /root
#WORKDIR /root
#ENTRYPOINT ["ping"]
#CMD ["google.com"]

How to start mysql and set up the mysql root password for a docker container?

I am trying to host a web server via docker.The web server needs mysql database.But I am failing to change the root password of mysql and also start the mysql and apache2 service.
So can someone help me to set the root password and start start the services.
Here is my try to setup the docker container.
FROM ubuntu:16.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get install apache2
RUN apt-get -q -y install mysql-server
CMD service mysql start

AWS ECS - Rails Container is not able to connect linked container mysql via mysqld.sock

I have setup application on AWS ECS , with repository, task and cluster management.
My Dockerfile is
FROM ruby:2.4.1
ENV LANG C.UTF-8
RUN apt-get update && \
apt-get install -y nodejs \
vim \
mysql-client --no-install-recommends && rm -rf /var/lib/apt/lists/*
WORKDIR /tmp
ADD ./Gemfile Gemfile
ADD ./Gemfile.lock Gemfile.lock
RUN bundle install
ENV APP_ROOT /workspace
RUN mkdir -p $APP_ROOT
WORKDIR $APP_ROOT
COPY . $APP_ROOT
EXPOSE 3000
CMD ["rails", "server", "-b", "0.0.0.0", "-e", "production"]
This is a repository which I have set up on the AWS ECS repository.
In the task destination I have set up two containers rail-app and mysql, which are linked to each other
From the rails-app, I am trying to connect RDS mysql instance, but as its throwing following error, I have added mysql container to support the connection which I think is not required as well
When I run the application with added task in the cluster service . Both containers runs fine, But on the rails-app container I got this error.
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (13)
When I run rails c production under docker exec -it containerid bash it runs fine and connects db properly. Here I can test active records as well
Please provide me a solution in task destination to share volume of mysql to rails application.
I am answering my own question here,
I have assigned env variables on the container section of task. Which were not loaded properly on the environment. When I have used figaro with application.yml It has started using variables as per the environment.
Mysql was not able to get the host from environment

docker to connect with mysql database of host system and dump the sql file into host system and then host a web application

I am new to Docker but i have read quite about it. Now my requirement is:
I will give my client a shell script which he would run on a base ubuntu os on a completely new system. The docker image should use the database of host system. The shell script will do all the prerequisites of installing docker, mysql, etc. and will run a docker image. As the image is not available locally, it will pull from docker repository.
Now my problem is that i dont want to give my client the sql dump file just like that. The dump is included in the image and once the images is run i want the image to connect to the host database and dump the data and then host the webapp.
My docker file is :
FROM ubuntu:14.04
MAINTAINER test_manoj
RUN pip install requirements.txt
ADD . /home/myapp/
RUN sudo apt-get install -y supervisor
WORKDIR /home/myapp/
EXPOSE 8000
EXPOSE 80
cmd ["supervisord", "-c", "/home/myapp/supervisord.conf"]
There are some more apt-get install-s but i didnt find it useful to mention here. So basically i am installing nginx, uwsgi, supervisor.
I have exposed port 8000 for socket uwsgi connections and port 80 for nginx.
My docker run command is :
docker run --detach --net=host -v /var/run/mysqld.sock:/var/run/mysqld/mysqld.sock manoj/mydocker
I am using -v to connect the host mysql to container's mysql.
I have already found a work around for my problem that is running
docker run --rm --detach --net=host -v /var/run/mysqld/mysqld.sock:/var/run/mysqld/mysqld.sock manoj/mydocker mysq -uroot -proot db_name < dump.sql
before the main run command. I know this works but is there any other way to do this? And is there any other way i can use host's mysql without providing -v tag?

How to start mysql server in docker container

I am creating docker container and base image is ubuntu:14.04. I have to start mysql server in that container and then I have to create databases and I have to give the permission to the users. Docker is new for me. I tried a lot but still whenever I go to that image and check for mysql server is running or not. Every time what I got is mysql server is stopped and my dbs are also not created.
This is my dockerfile
FROM ubuntu:14.04
MAINTAINER <name> <emailid>
RUN sudo apt-get update
RUN sudo apt-get install -y apache2 mysql-server libapache2-mod-auth-mysql php5-mysql php5 git
RUN sudo apt-get install -y vim
CMD sudo /usr/sbin/mysqld -u mysql
I tried a lot but i am not able to run mysql server in docker image.
Did you manually install it in your container?
Why do you not simply use:
docker run -d --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=secret -e MYSQL_DATABASE=mySchema mysql:5
That would start a container named mysql running a mysql daemon, setting the default root password to secret, creating a new schema called mySchema and expose the MySQL port 3306 to clients so that they could connect.
Then you could connect to that with any MySQL client using the root user with the specified password secret and create your tables within the created schema mySchema.
I had similar issue for ubuntu :14.04 while setting up druid cluster in the docker container, using CMD to start mysql fixed it for me.
CMD mysql start \
Druid related stuff
&& mysql stop
docker exec -it container_name/id bash
service mysql status to check on the service status
service mysql start to start the mysql service