Docker Community Forums

Share and learn in the Docker community.

TCP Java Socket custom timeouts not working only on docker

This code works perfectly on my machine default O.S but not in Docker, and I didn’t found any documentation about it.

    clientSocket = new Socket();
	SocketAddress sockaddr = new InetSocketAddress(propertyFile.getProperty("tcp.pod.ip"),
	clientSocket.connect(sockaddr, 150);


The part that does not work in docker is the clientSocket connect timeout(second parameter), it takes the default timeout instead the one I am passing to him. Everything else works perfectly.

The docker image I am using is


As sockets are from the O.S, if I can not set it from Java, can I set it in any way from the Dockerfile or docker-compose.yml?
May I need to install something as docker image is not entire linux?


version: '3'

    container_name: middleware
    image: hyperloopupv:middleware
    build: './receta' 
    - "5672:5672"
    - "15672:15672"
    - "1338:1338/udp"
    - "5556:5556/udp"
      - ./container-data/logs/data:/opt/mule/logs/data
      - ./container-data/logs/spacex_data:/opt/mule/logs/spacex_data
      - ./container-data/logs/alive:/opt/mule/logs/alive
      - ./container-data/apps:/opt/mule/apps


FROM rabbitmq:management


EXPOSE 5672 15672 1338 5556

ADD rabbitmq.config /etc/rabbitmq/

RUN chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.config

# APT update, wget and sudo
RUN apt-get update -y && apt-get upgrade -y
RUN apt-get install apt-utils -y
RUN apt-get install wget -y
RUN apt-get install sudo -y
RUN apt-get install vim -y

#Install java 8
RUN apt-get update && \
	apt-get install -y openjdk-8-jdk && \
	apt-get install -y ant && \
	apt-get clean && \
	rm -rf /var/lib/apt/lists/* && \
	rm -rf /var/cache/oracle-jdk8-installer;
RUN apt-get update && \
	apt-get install -y ca-certificates-java && \
	apt-get clean && \
	update-ca-certificates -f && \
	rm -rf /var/lib/apt/lists/* && \
	rm -rf /var/cache/oracle-jdk8-installer;

ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/

# Install mule
RUN wget && echo "d9279b3f0373587715613341a16483f3 mule-standalone-3.8.0.tar.gz" | md5sum -c
RUN tar xvzf mule-standalone-3.8.0.tar.gz && rm mule-standalone-3.8.0.tar.gz && mkdir mule && sudo mv /opt/mule-standalone-3.8.0/* /opt/mule/

# Define environment variables.
ENV mule.home /opt/mule/
VOLUME ["/opt/mule/logs", "/opt/mule/conf", "/opt/mule/apps", "/opt/mule/domains"]

WORKDIR  /opt/mule/apps/
#RUN echo "Downloading latest middleware" && wget
RUN sudo rm -r *
#COPY middleware

WORKDIR  /opt/
RUN chmod +x
RUN sed -i -e 's/\r$//'

CMD [ "./" ]

We have been testing for months but the telemetry was just from our O.S through two access points to the prototypes, so if an ack is not received because the protopype died I will see it(We were using this to see if there were communication)

With docker there is a proxy between the O.S and the docker engine so you will see always there is connection because the acks arrives always from the container to the O.S socket.

The solution to implement a keep alive in the application layer(you can not do this in the protocol layer).

This post explain it better: