I have one war file with the following MySQL setup; I wanted to compile it using Dockerfile so that I could utilise the mysql docker image.
However, I am missing/not properly configuring something, and as a result, I am receiving connection errors.
url: jdbc:mysql://localhost:3307/test-db
username: root
password: yum-hai-hum
DockerFile
FROM mysql:5.7
ADD test-db.sql /docker-entrypoint-initdb.d
EXPOSE 3307
ENV MYSQL_ROOT_PASSWORD=yum-hai-hum
ENV MYSQL_DATABASE=test-db
ENV MYSQL_USER=root
ENV MYSQL_PASSWORD=yum-hai-hum
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=build/libs/*.war
COPY ${JAR_FILE} app.war
ENTRYPOINT ["java","-jar","/app.war"]
Error:
Build and run command for image and container:
docker build -t="navin/java-app" .
docker run -e "SPRING_PROFILES_ACTIVE=dev" -p 8080:8084 -t navin/java-app
url: jdbc:mysql://localhost:3307/test-db
correct me if i`m wrong,
The host of Mysql server is container1-ip:3307
the war app is on container2, and it is trying to connect to localhost:3307
probably change host of url from localhost to something like 192.168.100.19. You can get the actual ip using command ifconfig on the first container
The default Docker container access host IP is 172.17.0.1 , If you have a MySQL port 3306 that maps to the host, you can use the
url: jdbc:mysql://172.17.0.1:3306/test-db
Related
Basically, I'm following my school assignment. It says to run a postgres image locally as so docker run --rm --name pg-docker -e POSTGRES_PASSWORD=docker -p 5432:5432 postgres:11. Then, it says I can connect to the database with the following info username: postgres, password: docker, url: jdbc:postgresql://localhost:5432/postgres. I've tried looking online, but can't find ways to do this in my command prompt (I'm on Windows). I'm wondering if this can only be refered to the Java code that I'm supposed to eventually do?
Then it says I should create database and generate Jooq records:
mvn clean package. There's a folder with some yaml and sql files. However, when I run this command, there's always a build failure.
Option 1 (dockerized).
Run
docker run --rm -it --net host postgres:11 psql -U postgres -h localhost -p 5432
and enter password docker when prompted.
Option 2 (native).
Download and install postgresql for windows from here: https://www.enterprisedb.com/downloads/postgres-postgresql-downloads
Then connect from PowerShell as following:
psql -U postgres -h localhost -p 5432
and enter password docker when prompted.
I have Java web app in docker container.
Now container is exposed on host's port 8080 from container's port 8080 by running docker run command.
docker run -d -p 8080:8080 --name myTomcat -v $(pwd)/out/artifacts/DockerJavaWebAppWarExploded:/usr/local/tomcat/webapps/ tomcat:latest
There is no other process running on 8080 port ,but i am not able to access the application from browser http://localhost:8080/.
Container logs :
Please help.
It would be appreciated.
Check if http://0.0.0.0:8080 returns values. If yes, you may add an enrty for 0.0.0.0 in your hosts file.
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.
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.