I created a docker swarm mode cluster and an app deployed. When the app tries to connect to the database, it fails. I able make it work with "docker run" but not in docker swarm mode.
Docker versions
Client:
Version: 1.13.0
API version: 1.25
Go version: go1.7.3
Git commit: 49bf474
Built: Tue Jan 17 09:58:26 2017
OS/Arch: linux/amd64
Server:
Version: 1.13.0
API version: 1.25 (minimum version 1.12)
Go version: go1.7.3
Git commit: 49bf474
Built: Tue Jan 17 09:58:26 2017
OS/Arch: linux/amd64
Experimental: false
Error:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Docker commands used
sudo docker network create -d overlay cross
sudo docker service create --name database -e MYSQL_ROOT_PASSWORD=admin --replicas 3 -p 3306:3306 --network cross mysql --max_allowed_packet=500M
sudo docker service create --name cross_app --replicas 2 -p 8000:8080 --network cross app1
Ports are open:
sudo docker exec -it 547ed77047c7 nc -v -z database 3306
database (10.0.0.2:3306) open
Related
I have been watching this before.
Moving Wordpress site to Docker: Error establishing DB connection
My Linux is centos VM, I try to create WordPress and MySQL(5.6~8).
It will be created but I can not connect DB.
This is my command (using swarm).
docker swarm init --advertise-addr=192.168.50.31
docker swarm join --token -secret token- 192.168.50.31:2377
docker network create -d overlay demo
docker service create --name wordpress
-p 80:80 --env WORDPRESS_DB_PASSWORD=root
--env WORDPRESS_DB_HOST=mysql
--network demo wordpress
docker service create --name mysql
--env MYSQL_ROOT_PASSWORD=root --env
MYSQL_DATABASE=wordpress --network demo
--mount
type=volume,source=mysql-data,destination=/var/lib/mysql mysql:5.6
I try to search it why. But did not find the answer.
Am Unable to start mysql with docker on Ubuntu. Get the following error:
db_1_cc1214d5085c | ERROR: mysqld failed while attempting to check
config db_1_cc1214d5085c | command was: "mysqld --verbose --help"
db_1_cc1214d5085c | db_1_cc1214d5085c | mysqld: error while loading
shared libraries: libpthread.so.0: cannot stat shared object:
Permission denied
Content of docker compose file:
version: '2.4'
services:
db:
image: mysql:5.7
ports:
- "32000:3306"
environment:
MYSQL_ROOT_PASSWORD: root
# restart: always
volumes:
- ./data/db:/var/lib/mysql
Docker details:
Client:
Version: 18.09.0
API version: 1.39
Go version: go1.10.4
Git commit: 4d60db4
Built: Wed Nov 7 00:48:57 2018
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.0
API version: 1.39 (minimum version 1.12)
Go version: go1.10.4
Git commit: 4d60db4
Built: Wed Nov 7 00:16:44 2018
OS/Arch: linux/amd64
Experimental: false
Also worth noting is that there is a non dockerized versionof MySQL installed and running on this server. Any help will be appreciated.
To start mysql service you'll need to have something like this in your docker-compose file
version: '3'
services:
<service-name>:
image: mysql:5.7
container_name: <container-name>
ports:
- "<host-port>:<container-port>"
environment:
- MYSQL_ROOT_PASSWORD=<root-password>
- MYSQL_DATABASE=<database-name>
volumes:
- <host-dir>:/var/lib/mysql
networks: ['stack']
networks:
stack:
driver: bridge
Make sure that <host-dir> you have permission with the current user executing the docker-compose up command.
The networks is used if you have multiple services that want to connect to the database they all should consume the same network which is stack in this example
looks like a permission problem on your host.
I start MySQL in docker by using below command:
docker run --name mysql-for-teamcity \
-e MYSQL_ROOT_PASSWORD=FAKE-ROOT-PW\
-v ~/MySQL/var_lib_mysql:/var/lib/mysql \
-p 3306:3306 \
-p 33060:33060 \
-it mysql
But TeamCity failed to connect the MySQL, the error message is :
I can connect to the MySQL in Terminal using below command:
mysql -u root --protocol=tcp -p
And database "teamcity" has also been created.
My Environment:
Mac OS X 10.14.1
Docker Desktop 2.0.0.0-mac81(29211)
TeamCity and MySQL are running in seperated Docker containers
Both Docker images tag is latest
The reason is TeamCity and MySQL are running in the separate containers, so when I specified "127.0.0.1" for TeamCity, it is not possible for it to connect to MySQL. Because they are simply not running in the same host.
The solution is using Docker Compose which set up a local network for containers by default.
Step 1: create a docker-compose.yml in an empty directory you want to place your TeamCity:
version: '3'
services:
TeamCity:
image: jetbrains/teamcity-server
ports:
- "8111:8111"
volumes:
- <your TeamCity dir>/data:/data/teamcity_server/datadir
- <your TeamCity dir>log:/opt/teamcity/logs
MySQL:
image: mysql
ports:
- "3306:3306"
volumes:
- <your TeamCity dir>/mysql:/var/lib/mysql
env_file:
- mysql.env
Step 2: create a mysql.env in the same directory:
MYSQL_ROOT_PASSWORD=YOUR-MYSQL-PASSWD
Step 3: run docker-compose up -d in the terminal in
Step 4: open "http://127.0.0.1:8111" in browser
Step 5: input "MySQL:3306" in the DataBase Host field.
I have problem with mysql-server container.
Post mysql with Exited(1) from docker has no solution for me included.
Here my workflow on windows 10.
0. Docker version:
Docker version 17.12.0-ce, build c97c6d6
1. My Dockerfile:
FROM mysql/mysql-server
ENV MYSQL_ROOT_PASSWORD root
ENV MYSQL_DATABASE blockchain
ENV MYSQL_USER block
ENV MYSQL_PASSWORD blockchain
COPY create_schema.sql /docker-entrypoint-initdb.d/create_schema.sql
EXPOSE 3306
Build command:
docker build -t mysqlserver .
Run command (option -d is used):
docker run -ti -p 3306:3306 --name mysqlserver1 -v C:/Users/user/sandbox/mysql:/var/lib/mysql -d --net testnetwork mysqlserver --innodb_use_native_aio=0
But result after start is: Exited (1) 11 minutes ago, declared path folder for database is initialized.
Where is my error ?
Thx for help
For mysql docker container, you need to specify the following parameters in your Dockerfile;
MYSQL_ROOT_PASSWORD
Initial Database to be created
Expose Port from the docker container to the host machine
For instance if you're creating the running mysql docker image using terminal, it could be: sudo docker run -e MYSQL_ROOT_PASSWORD=dev --name testdb -p 3800:3600 -d mysql:8.0.17
I am trying to connect a container with tomcat to a container with mysql in order to deploy an app. I have reproduced the same into a vagrant machine (tomcat 6, mysql 5.6) but now I want to do it using docker containers.
I used this answer here with some extra additions.
For the mysql container I run:
sudo docker run --name mysql -e MYSQL_USER=root -e MYSQL_ROOT_PASSWORD=admin -e MYSQL_DATABASE=my_database_name -d mysql:5.6
For the Tomcat container
docker run -d -p 8080:8080 --name tomcat --link mysql:mysql -v $PWD/webapp:/usr/local/tomcat/webapps tomcat:6
Also I have the folder webapp/with_my_app.war. So far so good.
This specific app needs some config in the WEB-INF/context.xml file, so I run
docker exec -it tomcat bash
Then I updated and installed vim and finally edit the context.xml file and restarted tomcat.
But I cannot access my app at localhost:8080/with_my_app
What am I missing?
Include --cap-add SYS_PTRACE while running tomcat container.
docker run -d -p 8080:8080 --cap-add SYS_PTRACE ......