Cannot detach from Docker console with Java process on it - java

I'm not able to detach from a Docker container after I attached to it.
Dockerfile to define the container:
FROM adoptopenjdk/openjdk16:debian
WORKDIR /app
STOPSIGNAL SIGTERM
RUN apt-get update && apt-get install -y curl && apt clean
CMD curl -so server.jar https://ci.tivy.ca/job/Airplane-1.17/lastSuccessfulBuild/artifact/launcher-airplane.jar && java -jar server.jar
Build the container with: docker build -t minecraft .
docker-compose file:
version: "3.7"
services:
mc:
container_name: mc
ports:
- 25565:25565
image: minecraft
volumes:
- type: bind
source: /root/mc
target: /app
Start the container with: docker-compose up mc
I tryed to attach to console with docker attach mc, it works. But I'm not unable to detach from screen. Ctrl+C not work. Ctrl+P and Ctrl+Q not work. Writing stop (command that will stop the java process) not working
I tryed to attach with docker attach --detach-keys="ctrl-d" mc but is not working
Java process never ends

Found fix myself. Need to insert stdin_open and ttyin docker-compose file. New docker-compose.yml:
version: "3.7"
services:
mc:
container_name: mc
ports:
- 25565:25565
image: minecraft
volumes:
- type: bind
source: /root/mc
target: /app
stdin_open: true
tty: true
Will set this answer as solution in two days because of stackoverflow rules

Related

Gitlab-ci docker inside java image

To use a integration test library https://www.testcontainers.org/" I need a image with java a docker installed at same time.
I'm trying o use this stage:
test:
stage: test
image: gradle:jdk16
services:
- docker:latest
script:
- docker --version
- chmod +x ./gradlew
- export GRADLE_USER_HOME=`pwd`/.gradle
- ./gradlew test --stacktrace
rules:
- !reference [.rules_merge_request, rules]
But It does not work:
$ docker --version
/scripts-33119345-2089057982/step_script: line 154: docker: command not found
Any help?
The image gradle:jdk16 does not include the docker client. You'll have to install it in your job. Additionally, you'll need to use the service docker:dind in your services: configuration (not docker:latest)
test:
stage: test
image: gradle:jdk16
services:
- docker:dind # use the docker-in-docker image
before_script: # install docker
- apt update && apt install --no-install-recommends -y docker.io
script:
- docker --version
Running this on gitlab.com runners, you should see an output like this:

Use Java with Airflow and Docker

I have a use case where I want to run a jar file via Airflow, all of which has to live in a Docker Container on Mac.
I have tried installing java separately and also, tried mounting my JAVA_HOME(host) onto the container.
This is my docker-compose.yaml:
airflow:
image: 'puckel/docker-airflow:1.10.9'
hostname: airflow
container_name: airflow
volumes:
- ${PWD}/airflow/dags:/usr/local/airflow/dags
- ${JAVA_HOME}:/usr/local/bin/java //FWD MOUNTING JAVA_HOME
This way, I get a java directory inside /usr/local/bin/ with the data but java -version returns Permission denied.
Changing it to ${JAVA_HOME}/bin/java:/usr/local/bin/java returns exec format error.
What is the correct way to handle this use case?
I think that you're getting Permission denied because you are running docker with user airflow.
Can you try to run it as root? (this is risky! don't use in production - it is just an effort to temporary workaround). Avoid using root user!
airflow:
image: 'puckel/docker-airflow:1.10.9'
hostname: airflow
container_name: airflow
user: root
volumes:
- ${PWD}/airflow/dags:/usr/local/airflow/dags
- ${JAVA_HOME}:/usr/local/bin/java
EDIT:
Instead of mounting your local java, consider installation of a seperate one:
airflow:
build:
context: .
dockerfile: Dockerfile
hostname: airflow
container_name: airflow
volumes:
- ${PWD}/airflow/dags:/usr/local/airflow/dags
and add the Dockerfile in the same directory:
FROM puckel/docker-airflow:1.10.9
USER root
RUN mkdir -p /usr/share/man/man1
RUN apt-get update && apt-get install -y default-jdk && apt-get clean
USER airflow

How to install java using docker compose?

I am building an node mongo project.
I am using docker compose for the project.
here is my dockerFile
FROM node:carbon
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
CMD [ "npm", "start" ]
Here is docker-compose.yml
version: "2"
services:
app:
container_name: app
restart: always
build: .
ports:
- "3000:3000"
links:
- mongo
mongo:
container_name: mongo
image: mongo
volumes:
- ./data:/data/db
ports:
- "27017:27017"
Here I also want to install java using docker-compose. As I will need java for elastic search and for other purposes. So can any one help about how to install java using docker-compose in this project.
Docker-compose is a tool used to launch multiple containers from a single .yaml file.
Add this line to your Dockerfile to install Java:
RUN apt-get update && \
apt-get install -y openjdk-8-jdk && \
apt-get install -y ant && \
apt-get clean;

Simple docker-compose to execute a Jar

I am trying to set up a very simple Docker container, that will execute a Jar file. I want an image that will run a simple Jar. I dont need anything else special.
So far my docker-compose.yml looks like this, but it doesn't start correctly:
version: "3.3"
services:
myapp:
image: openjdk:8
container_name: "myapp"
restart: always
ports:
- 8091:8091
volumes:
- "./meanwhile-in-hell.jar:/app.jar"
command: ['java', '-jar', '/app.jar']
STATUS
Restarting (1) 2 seconds ago
Using the command: ['java', '-jar', '/app.jar'] option, I see this in the Docker logs:
Error: Invalid or corrupt jarfile /app.jar
If I change to use entrypoint: [ "sh", "-c", "java -jar /app.jar" ], I see the same error.
The Jar file is absolutely fine and not corrupt. I have run it manually on another tomcat:8-alpine container I have running and it starts up successfully.

dockerfile to run java exiting instantly

I have the following docker file to run my java application
FROM gidikern/rhel-oracle-jre
RUN mkdir /application
WORKDIR /application
CMD "java -Dspring.profiles.active=sprofileName -jar my.war --spring.config.location=./application.properties > app.log > 2>&1"
and i'm running using docker-compose:
backend_app:
restart: always
image: my-app-runner:latest
ports:
- "8080:8080"
volumes:
- ./app/my.war:/application/my.war:Z
- ./app/application.properties:/application/application.properties:Z
- /srv/docker/backend_app/logs:/application/my.log:Z
tty: true
however when i start i get that my app exited with code 0 constantly.
I can't find what is wrong.
The problem was actually with my base image gidikern/rhel-oracle-jre
I tested and even basic commands like ls didn't work..
Switched to openjdk for now and it is fine.
Very probably there's an error in your application. To debug I suggest you to run the container in shell and to execute the java command manually to see what's happening.
In other words:
docker run -it --name app-debug my-app-runner:latest /bin/bash
java -Dspring.profiles.active=sprofileName -jar my.war --spring.config.location=./application.properties

Categories