i have 2 docker file
1. mysql-dockerfile
FROM mysql:5.5
EXPOSE 3306
ENV MYSQL_ROOT_PASSWORD root
ENV MYSQL_DATABASE ToDoList
command used to build dockerfiles are as below
sudo docker build -t mysql-img -f mysql-dockerfile .
sudo docker run -d --name mysqlcontainer -p 3030:3306 mysql-img
2. java-dockerfile
FROM openjdk:8-jre-alpine
EXPOSE 9090
WORKDIR /usr/src
COPY target/*.war todoApp.war
CMD ["java","-jar","todoApp.war"]
command used to build dockerfiles are as below
sudo docker build -t java-img -f java-dockerfile .
docker run --name javacontainer -d -p 4040:9090 java-img
spring boot application consist jdbc url as follow
spring.datasource.url=jdbc:mysql://localhost:3030/ToDoList
i am not able to start project because spring boot application in docker is not able to connect mysql db which is in another container.
one solution i found is to bring two docker container in one docker network or link docker container.
can anyone please suggest good solution, modified docker run command and modified jdbc url.
Put them into one network and use container names as hostnames:
docker network create foo
docker run --network=foo --name mysqlcontainer -d mysql-img
docker run --network=foo --name javacontainer -d java-img
Dont expose ports - they are exposed automatically between containers inside network.
To connect inside, use mysqlcontainer:3306 and javacontainer:9090.
To connect from host, you will need port exposing.
Related
I just started exploring docker today and I've been trying to spin-up Spring Boot Web app backed by MySQL DB.
I pulled a MySQL container and ran it using:
docker run -t --name mysql-docker-container -p 3306:3306 -e MYSQL_ROOT_PASSWORD=**** -e MYSQL_DATABASE=spring_app_db -e MYSQL_USER=app_user -e MYSQL_PASSWORD=**** -d mysql
My application.properties file:
spring.datasource.url=jdbc:mysql://0.0.0.0:3306/spring_app_db?autoReconnect=true&failOverReadOnly=false&maxReconnects=10
spring.datasource.username=app_user
spring.datasource.password=test123
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
with this, when I run my spring boot in IDE it's able to connect and perform CRUD on db table.
However, when I try to deploy it on docker and link with MySQL container it throws Connection Refused error.
My Dockerfile:
FROM openjdk:11
LABEL maintainer="baljinder#gmail.com"
VOLUME /tmp
EXPOSE 8080
ADD target/demo-0.0.1-SNAPSHOT.jar bootmysql.jar
ENTRYPOINT ["java", "-jar", "bootmysql.jar"]
The command I'm using to run docker image of the boot:
docker run -t --name spring-jpa-container -p 8080:8080 --link mysql-docker-container:mysql spring-jpa-app
Can someone please help with this. I've tried deploying both on the same container network by creating a docker network (docker network create -d bridge sql_spring_network) but the error persists.
When using the legacy linking of containers using the --link flag. The "linked" container is available as a host in the running container with it's container name. So in your case, the mysql container is available in your app container with hostname mysql.
Your database url, therefore should be: jdbc:mysql://mysql:3306/spring_app_db?autoReconnect=true&failOverReadOnly=false&maxReconnects=10
use:
jdbc:mysql://mysql-docker-container:3306/spring_app_db?autoReconnect=true&failOverReadOnly=false&maxReconnects=10
replace:
jdbc:mysql://0.0.0.0:3306/spring_app_db?autoReconnect=true&failOverReadOnly=false&maxReconnects=10
I'm trying to test a microservice running from docker.
Without docker I can access it on http://localhost:9999/
When I build the image, run it and try the same address http://localhost:9999/ I get err_connection_refused
In my dockerfile I
EXPOSE 9999
And when running the image I map ports
docker run -i -t 6bcb62617b00 -p 9999:9999
But this dosn't help.
`Docker-machine` ls returns `tcp://192.168.99.100:2376`
I am using docker quickstart terminal for testing.
This is the message I get when running the image Tomcat started on port(s): 9999
docker ps
Seems like it had something to do with the way I run it.
Here
docker run -d --network=name -p 9999:9999 beeline/dim_source_taxon
Instead of image id I use repository to start microservice and when I try
docker ps
I get
Also, instead of localhost I have to use the host provided by comand docker-machine ls
I want to access mongo db running on url: "xyz" (remote host), and in my spring boot application properties, I have mentioned the mongodb url to "xyz".
Now when i run this application inside a docker container, it can not connect to remote url, and shows the connection refused error.
How do We access the remote database from inside a container ?
Below is my DockerFile
FROM openjdk:8-jdk-alpine
RUN apk add --no-cache bash
RUN apk add --no-cache curl
EXPOSE 8090
COPY target/<jar file> /application.jar
RUN mkdir /logs
RUN /bin/sh -c "apk add --no-cache bash"
ENTRYPOINT ["/usr/bin/java"]
CMD ["-DLOG_DIR=/logs", "-DLOG_FILE=application.log", "-jar", "-Dspring.profiles.active=local", "-Xmx1g", "/application.jar", "&"]
My Application.properties:
spring.data.mongodb.uri = <mongodb-url>
I build my docker image as:
docker build -t app:app .
I run the docker image as:
docker run -d <imageId>
Following command gets the job done.
docker run --net=host <imageId>
Be careful with this command because --net=host makes the container share network with the host. The network of the container will no longer be isolated.
I have a little experience with docker-compose and Laravel, this set goes fine, but how could I make the same with dspace?
I would like to have work directory in my host, not all into container.
I have tried dspace-docker that is in dockerhub, is this one: https://github.com/4Science/dspace-docker, but I had troubles wit him.
Thank you!
The following Docker images can be used to run DSpace locally. There is not yet a published Docker Compose file.
- https://hub.docker.com/r/dspace/dspace-tomcat/
- https://hub.docker.com/r/dspace/dspace-postgres-pgcrypto/
The following page describes how to utilize these images on either Windows or MacOS: https://github.com/DSpace-Labs/DSpace-Docker-Images/blob/master/tutorial.md
Here are the key steps.
Clone DSpace
Configure a local.cfg file that assumes DSpace will run in a container. [dspace-install] will be within the container.
Run the DSpace maven build on your workstation
Run the DSpace ant update in a container to install the code at [dspace-install]
The MacOS setup is described here. See the link above for Windows.
docker network create dspacenet
docker volume create pgdataD6
docker run -it -d --network dspacenet -p 5432:5432 --name dspacedb -v pgdataD6:/pgdata -e PGDATA=/pgdata dspace/dspace-postgres-pgcrypto
docker run -it --rm --network dspacenet -v "$(pwd)"/dspace/target/dspace-installer:/installer -v dspaceD6:/dspace -w /installer dspace/dspace-tomcat ant update clean_backups
docker run -it --network dspacenet -v dspaceD6:/dspace -p 8080:8080 --name dspacetomcat -e DSPACE_INSTALL=/dspace dspace/dspace-tomcat
I have a mysql container and a service container that needs to connect to the mysql container.
I created a networking with docker network create chrisbolton
I am spinning up the mysql container with
docker run --name chrisbolton-mysql -v /Users/Bolton/chrisbolton-data:/var/lib/mysql --network chrisbolton -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=chrisbolton -d mysql:latest
I am spinning up the service container with
docker run -p 8080:8080 --name chrisbolton-service --network chrisbolton --link chrisbolton-mysql:mysql -d chrisbolton-service
However, I know that link is deprecated and I need to move to only using networks. But if I remove the link here the two containers cannot communicate.
I am connecting to mysql with the following config:
#disbale Spring banner
spring.main.banner-mode=off
spring.datasource.url=jdbc:mysql://mysql:3306/chrisbolton
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
I have done a docker network inspect chrisbolton to get the IPAddresses and have tried changing my config file to point to that directly. But still not sure why it won't connect.
datasource.url is not correct, you should specify the name of the container to which you want to connect. There are better options than using the name of service. You can use aliases or hostname.
While in this case, as you indicated in comments, datasource.url needs to be jdbc:mysql://chrisbolton-mysql:3306/chrisbolton