I am new to Docker and nosql, I created a Oracle Linux VM (ipAddr 192.168.10.2) on my windows machine.
Further I created docker container (on this VM ) for kvlite and run my nosql-container as below:
$ docker run --name nosql-container -p 5000:5000 -d kvlite:latest
followed by below commands:
$ docker exec -it nosql-container bash
# java -jar lib/kvcli.jar -host localhost -port 5000
kv-> connect store -host localhost -port 5000 -name kvstore ;
This works fine till here and I believe my Docker container for kvlite is up and running fine.
Now I need to create a Client Java program from my windows machine to access this kvlite (running in docker container on a VM)
To accomplish I downloaded kvclient.jar file and put that in my classpath.
The Java code-snippet below:
KVStore store = KVStoreFactory.getStore(new KVStoreConfig("kvstore", "192.168.10.2:5000"));
This throws an exception:
oracle.kv.FaultException: Could not contact any RepNode at: [192.168.10.2:5000] (12.1.4.0.9)
....
Caused by: java.rmi.UnknownHostException: Unknown host: ecfe59938ea4; nested exception is:
Any help appreciated in advance.
I resolved the issue by adding a param --net=host when running nosql-container
$ docker run --name nosql-container --net=host -p 5000:5000 -d kvlite:latest
Now instead of IPAddress you can use VM hostname in Java Client code to access kvlite DB.
KVStore store = KVStoreFactory.getStore(new KVStoreConfig("kvstore", "VMHostname:5000"));
Related
This is the error I get:
docker run -dit openjdk:8-jdk-alpine
docker images
docker container ls
docker container exec flamboyant_knuth ls /tmp
docker container cp target/HelloTm-0.0.1-SNAPSHOT.jar flamboyant_knuth:/tmp
docker container exec flamboyant_knuth ls /tmp
docker container commit flamboyant_knuth syedwn14/hellotm-0.0.1-snapshort:manual1
docker images
docker run syedwn14/hellotm-0.0.1-snapshort:manual1
docker container commit --change="CMD ["java","-jar","/tmp/hellotm-0.0.1-snapshort.jar"]" flamboyant_knuth syedwn14/hellotm-0.0.1-snapshort:manual2
docker run -p 8080:8080 syedwn14/hellotm-0.0.1-snapshort:manual2
Error:
/bin/sh: [java,-jar,/bin/sh/hellotm-0.0.1-snapshort.jar]: not found
Any help will be great.
I faced the same issue, was working on Windows.
Actual Problem
Running the following command docker container commit --change="CMD ["java","-jar","/tmp/hellotm-0.0.1-snapshort.jar"]" flamboyant_knuth syedwn14/hellotm-0.0.1-snapshort:manual2 from cmd or powershell adds Windows line endings (\r\n called CRLF).
On running the following command, the docker container is started.
docker run -p 8080:8080 syedwn14/hellotm-0.0.1-snapshort:manual2
Once the docker container has started it tries to execute the bash command.
["java","-jar","/tmp/hellotm-0.0.1-snapshort.jar"]
But instead throws an error
/bin/sh: [java,-jar,/bin/sh/hellotm-0.0.1-snapshort.jar]: not found.
For the bash command to be executed properly we need to convert the line endings of this command to Linux EOL (\n called "LF").
Easiest Solution that I use:
Install Git Bash (it provides a UNIX style command interface).
Run the following command from Git Bash docker container commit --change="CMD ["java","-jar","/tmp/hellotm-0.0.1-snapshort.jar"]" flamboyant_knuth syedwn14/hellotm-0.0.1-snapshort:manual2.
This will ensure that the line endings are Linux EOL.
Note: On running docker container exec flamboyant_knuth ls /tmp from Git Bash you will face the following error message.
$ docker container exec elated_fermat ls /tmp
ls: C:/Users/<user_name>/AppData/Local/Temp: No such file or directory
Instead run the command on either cmd or powershell.
Here's the Link to download Git Bash for Windows
This is my docker file
FROM openjdk:8-jre-slim
RUN mkdir /app
COPY dept-1.0.jar /app
CMD java -jar /app/dept-1.0.jar
EXPOSE 8080
The docker image can be run without any issues if I were to run like without port-forward
docker run --name=department dept:latest
But with port-forward docker run --name=department dept:latest -p 8082:8080 I see this error -
docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"-p\": executable file not found in $PATH": unknown.
Can someone help pls ?
I changed the following in the Dockerfil
CMD java -jar /app/dept-1.0.jar
to
ENTRYPOINT ["java", "-jar", "/app/dept-1.0.jar"]
This solved my issue.
I have spring boot project with one page - Hello word!
JAR app perfectly works in a docker container.
But in my host computer docker does not want run app. Page not available.
docker ps say:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4b34df7e3986 quality-serv "java -jar quality-s…" 21 hours ago Up 20 hours 0.0.0.0:8080->8080/tcp quality-service_con
But netstat (admin) does not find listeners on same port
App work only in the container, not in a personal computer.
I try many dif commands:
docker run -p 8080:8080 -d...
docker run --expose 9990 -p 9990:9990 -p 8080:8080 -it
docker run -d --net=host -P
docker run -it -d -p
They did not help.
Run yaml (docker-compose) with image description did not help too...
First make sure, when creating the container, the Dockerfile was exposing port 8080 EXPOSE 8080.
Then, if your application runs on port 8080, docker run -p 8080:8080 should be the command. Don't add -d by now, so you don't run detached mode and can see the logs.
Is it possible to copy an existing WebSphere profile and run it on WebSphere in Docker?
I am doing some research on containerization, virtualization, etc. and am currently working with Docker. Getting WebSphere up and running on Docker is simple enough:
docker run --name wasserver -h wasserver -p 9043:9043 -p 9443:9443 -d ibmcom/websphere-traditional:install
What I'd like to do is use a profile from another WebSphere instance and run that on the Docker WebSphere. I have tried to do the following in an attempt to mount a directory that contains the profile in question, and to run same:
docker run -v /opt/WebSphere/WAS8_5/:/WASDIR --name myprofileserver -h myprofileserver -p 9043:9043 -p 9443:9443 -d ibmcom/websphere-traditional:install -e PROFILE_NAME=/WASDIR/profiles/myprofile1
The end result of this command is that the container is created, but does not run:
docker: Error response from daemon: oci runtime error: exec: "-e": executable file not found in $PATH
Perhaps there is a switch, setup, or other configuration I am missing here?
The last argument to docker run is the command you want to run inside the container (or the name of the image if you're running the default entrypoint / cmd). You just need to move your environment variable definition back in the command like this:
docker run -v /opt/WebSphere/WAS8_5/:/WASDIR --name myprofileserver -h myprofileserver -p 9043:9043 -p 9443:9443 -d -e PROFILE_NAME=/WASDIR/profiles/myprofile1 ibmcom/websphere-traditional:install
I have a Dockerfile based on the spring guide about docker. My application consumes some private data, so I want to pass these parameters through environment variables. When I run a docker container:
docker run -p 8080:8080 -t myname/myapplication --env-file=~/env.list
it appears that the variables are not set and the application can't see them, what do I do wrong? How to pass these parameters?
env.list:
ACCOUNT_ID=my_account_id
ACCOUNT_PASSWORD=my_secret_password
My ENTRYPOINT:
ENTRYPOINT java -Djava.security.egd=file:/dev/./urandom -jar $APPLICATION_NAME
I think
docker run
takes all parameters before the image and the command. If I do
docker run -t --env-file=env.list ubuntu sh -c "while true; do echo world; sleep 100 ;done"
and then
docker exec -it container_id env
I get
HOSTNAME=195f18677a91
TERM=xterm
ACCOUNT_ID=my_account_id
ACCOUNT_PASSWORD=my_secret_password
HOME=/root
Try
docker run -p 8080:8080 --env-file=~/env.list -t myname/myapplication
This works very well:
cat <<EOF > test.env
MYVAR=test
EOF
docker run -it --env-file test.env busybox env | grep MYVAR
That will print as expected:
MYVAR=test
In your case in your Java application you can access the environment variables via System.getenv().