Angular cant connect to spring boot endpoints in docker compose
I moved my spring app (backend) and angular app (frontend) to docker compose - all looks works well, but when angular send GET/POST to spring boot gets no reponse.
Dockerfile:
FROM java
VOLUME /tmp
ADD build/libs/backend.jar spring-boot-app.jar
RUN bash -c 'touch /spring-boot-app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/spring-boot-app.jar"]
docker-compose.yml
version: '3'
backend:
container_name: "backend"
restart: always
image: app:latest
depends_on:
- mysql
- mongodb
ports:
- 8087:8080
frontend:
container_name: "frontend"
image: frontend:latest
ports:
- 4201:4200
Dockerfile angular:
FROM node:9.6.1
RUN mkdir /usr/src/app
WORKDIR /usr/src/app
ENV PATH /usr/src/app/node_modules/.bin:$PATH
COPY package.json /usr/src/app/package.json
RUN npm install
RUN npm install -g @angular/cli@1.7.1
COPY . /usr/src/app
CMD ng serve --host 0.0.0.0 --prod
My api const:
export const environment = {
production: true,
apiUrl: "http://backend:8080"
};
When I go to localhost:4201 - I can see my frontend, when I go to localhost:8087 I can see my backend and endpoints works well, but Angular doesnt get response:
For couple of time I'm trying to figure out - I will be grateful for every advice.
angular spring spring-boot docker docker-compose
add a comment |
I moved my spring app (backend) and angular app (frontend) to docker compose - all looks works well, but when angular send GET/POST to spring boot gets no reponse.
Dockerfile:
FROM java
VOLUME /tmp
ADD build/libs/backend.jar spring-boot-app.jar
RUN bash -c 'touch /spring-boot-app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/spring-boot-app.jar"]
docker-compose.yml
version: '3'
backend:
container_name: "backend"
restart: always
image: app:latest
depends_on:
- mysql
- mongodb
ports:
- 8087:8080
frontend:
container_name: "frontend"
image: frontend:latest
ports:
- 4201:4200
Dockerfile angular:
FROM node:9.6.1
RUN mkdir /usr/src/app
WORKDIR /usr/src/app
ENV PATH /usr/src/app/node_modules/.bin:$PATH
COPY package.json /usr/src/app/package.json
RUN npm install
RUN npm install -g @angular/cli@1.7.1
COPY . /usr/src/app
CMD ng serve --host 0.0.0.0 --prod
My api const:
export const environment = {
production: true,
apiUrl: "http://backend:8080"
};
When I go to localhost:4201 - I can see my frontend, when I go to localhost:8087 I can see my backend and endpoints works well, but Angular doesnt get response:
For couple of time I'm trying to figure out - I will be grateful for every advice.
angular spring spring-boot docker docker-compose
You are exposing port8087
, so you probably should change the port number here:apiUrl: "http://backend:8087"
– Ervin Szilagyi
Jan 1 at 16:12
I exposing it only to my machine - inside docker should see port 8080 as I did inports: - 8087:8080
– Adrian Wąt
Jan 1 at 16:14
1
Yes, but your browser makes the request to the back-end, not the angular container. The angular container is only hosting the content.
– Ervin Szilagyi
Jan 1 at 16:15
add a comment |
I moved my spring app (backend) and angular app (frontend) to docker compose - all looks works well, but when angular send GET/POST to spring boot gets no reponse.
Dockerfile:
FROM java
VOLUME /tmp
ADD build/libs/backend.jar spring-boot-app.jar
RUN bash -c 'touch /spring-boot-app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/spring-boot-app.jar"]
docker-compose.yml
version: '3'
backend:
container_name: "backend"
restart: always
image: app:latest
depends_on:
- mysql
- mongodb
ports:
- 8087:8080
frontend:
container_name: "frontend"
image: frontend:latest
ports:
- 4201:4200
Dockerfile angular:
FROM node:9.6.1
RUN mkdir /usr/src/app
WORKDIR /usr/src/app
ENV PATH /usr/src/app/node_modules/.bin:$PATH
COPY package.json /usr/src/app/package.json
RUN npm install
RUN npm install -g @angular/cli@1.7.1
COPY . /usr/src/app
CMD ng serve --host 0.0.0.0 --prod
My api const:
export const environment = {
production: true,
apiUrl: "http://backend:8080"
};
When I go to localhost:4201 - I can see my frontend, when I go to localhost:8087 I can see my backend and endpoints works well, but Angular doesnt get response:
For couple of time I'm trying to figure out - I will be grateful for every advice.
angular spring spring-boot docker docker-compose
I moved my spring app (backend) and angular app (frontend) to docker compose - all looks works well, but when angular send GET/POST to spring boot gets no reponse.
Dockerfile:
FROM java
VOLUME /tmp
ADD build/libs/backend.jar spring-boot-app.jar
RUN bash -c 'touch /spring-boot-app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/spring-boot-app.jar"]
docker-compose.yml
version: '3'
backend:
container_name: "backend"
restart: always
image: app:latest
depends_on:
- mysql
- mongodb
ports:
- 8087:8080
frontend:
container_name: "frontend"
image: frontend:latest
ports:
- 4201:4200
Dockerfile angular:
FROM node:9.6.1
RUN mkdir /usr/src/app
WORKDIR /usr/src/app
ENV PATH /usr/src/app/node_modules/.bin:$PATH
COPY package.json /usr/src/app/package.json
RUN npm install
RUN npm install -g @angular/cli@1.7.1
COPY . /usr/src/app
CMD ng serve --host 0.0.0.0 --prod
My api const:
export const environment = {
production: true,
apiUrl: "http://backend:8080"
};
When I go to localhost:4201 - I can see my frontend, when I go to localhost:8087 I can see my backend and endpoints works well, but Angular doesnt get response:
For couple of time I'm trying to figure out - I will be grateful for every advice.
angular spring spring-boot docker docker-compose
angular spring spring-boot docker docker-compose
asked Jan 1 at 15:52
Adrian WątAdrian Wąt
818
818
You are exposing port8087
, so you probably should change the port number here:apiUrl: "http://backend:8087"
– Ervin Szilagyi
Jan 1 at 16:12
I exposing it only to my machine - inside docker should see port 8080 as I did inports: - 8087:8080
– Adrian Wąt
Jan 1 at 16:14
1
Yes, but your browser makes the request to the back-end, not the angular container. The angular container is only hosting the content.
– Ervin Szilagyi
Jan 1 at 16:15
add a comment |
You are exposing port8087
, so you probably should change the port number here:apiUrl: "http://backend:8087"
– Ervin Szilagyi
Jan 1 at 16:12
I exposing it only to my machine - inside docker should see port 8080 as I did inports: - 8087:8080
– Adrian Wąt
Jan 1 at 16:14
1
Yes, but your browser makes the request to the back-end, not the angular container. The angular container is only hosting the content.
– Ervin Szilagyi
Jan 1 at 16:15
You are exposing port
8087
, so you probably should change the port number here: apiUrl: "http://backend:8087"
– Ervin Szilagyi
Jan 1 at 16:12
You are exposing port
8087
, so you probably should change the port number here: apiUrl: "http://backend:8087"
– Ervin Szilagyi
Jan 1 at 16:12
I exposing it only to my machine - inside docker should see port 8080 as I did in
ports: - 8087:8080
– Adrian Wąt
Jan 1 at 16:14
I exposing it only to my machine - inside docker should see port 8080 as I did in
ports: - 8087:8080
– Adrian Wąt
Jan 1 at 16:14
1
1
Yes, but your browser makes the request to the back-end, not the angular container. The angular container is only hosting the content.
– Ervin Szilagyi
Jan 1 at 16:15
Yes, but your browser makes the request to the back-end, not the angular container. The angular container is only hosting the content.
– Ervin Szilagyi
Jan 1 at 16:15
add a comment |
1 Answer
1
active
oldest
votes
The Angular application is not running in a container, it's served as static files to be run in the browser. You have mapped the 8087 port outside the container to the 8080 port inside it, so just use the following URL for the API calls from Angular: http://<your-machine-or-domain-name>:8087
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996836%2fangular-cant-connect-to-spring-boot-endpoints-in-docker-compose%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The Angular application is not running in a container, it's served as static files to be run in the browser. You have mapped the 8087 port outside the container to the 8080 port inside it, so just use the following URL for the API calls from Angular: http://<your-machine-or-domain-name>:8087
add a comment |
The Angular application is not running in a container, it's served as static files to be run in the browser. You have mapped the 8087 port outside the container to the 8080 port inside it, so just use the following URL for the API calls from Angular: http://<your-machine-or-domain-name>:8087
add a comment |
The Angular application is not running in a container, it's served as static files to be run in the browser. You have mapped the 8087 port outside the container to the 8080 port inside it, so just use the following URL for the API calls from Angular: http://<your-machine-or-domain-name>:8087
The Angular application is not running in a container, it's served as static files to be run in the browser. You have mapped the 8087 port outside the container to the 8080 port inside it, so just use the following URL for the API calls from Angular: http://<your-machine-or-domain-name>:8087
answered Jan 1 at 20:51
YoukouleleYYoukouleleY
2,6291826
2,6291826
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996836%2fangular-cant-connect-to-spring-boot-endpoints-in-docker-compose%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You are exposing port
8087
, so you probably should change the port number here:apiUrl: "http://backend:8087"
– Ervin Szilagyi
Jan 1 at 16:12
I exposing it only to my machine - inside docker should see port 8080 as I did in
ports: - 8087:8080
– Adrian Wąt
Jan 1 at 16:14
1
Yes, but your browser makes the request to the back-end, not the angular container. The angular container is only hosting the content.
– Ervin Szilagyi
Jan 1 at 16:15