I have two docker containers. One is java server, running on 8080 port with rest API /drivers. Another container is simple nodejs server with index.html page where ajax call is being performed to save new driver. URL in js file is: const URL = "http://storage:8080/drivers";
When I run them using just docker and created for them network, communication between them works fine. But when I run both containers using docker-compose, then I get status "(failed) net::ERR_NAME_NOT_RESOLVED"
When I open bash of any of this containers and run 'ping storage', I normally receive packets.
What am I missing?
DockerFile for java server:
FROM java:8
VOLUME /tmp
ADD target/docker-project-1.0-SNAPSHOT.jar app.jar
EXPOSE 8080
RUN sh -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
DockerFile for nodejs server:
FROM node:argon
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
RUN npm install connect serve-static
COPY . /usr/src/app
EXPOSE 8081
CMD ["node", "server.js"]
docker-compose.yml file:
version: '2.1'
services:
client:
image: glasierr/js-client
networks:
default:
aliases:
- "client"
links:
- "storage"
ports:
- "8081:8081"
storage:
image: glasierr/drivers-storage
networks:
default:
aliases:
- "storage"
ports:
- "8080:8080"
expose:
- "8080"
JS script:
const URL = "http://storage:8080/drivers";
$.ajax({
headers: {
'Content-Type': 'application/json'
},
type: "POST",
url: URL,
data: JSON.stringify({
licenceId: licenceId,
name: name,
surname: surname,
email: email
}),
dataType: "json"
});