Create the following Dockerfile and start it from docker-compose.
The version is also listed. It's not that you can't do it without this version.
Only the items required this time are listed.
--Repository root - docker - docker-nginx - Dockerfile - nginx.conf - docker-springboot - Dockerfile - docker-springboot-local - Dockerfile - docker-compose.yml - gradlew - gradlew.bat
Nginx
docker/docker-nginx/Dockerfile
FROM nginx:1.15.0
ADD nginx.conf /etc/nginx/conf.d/nginx.conf
Not a Dockerfile, but one used by scripts in the Dockerfile.
docker/docker-nginx/nginx.conf
server {
listen 8080;
charset utf-8;
access_log off;
location / {
proxy_pass http://app:8090;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /static {
access_log off;
expires 30d;
alias /app/static;
}
}
I don't know if this is the best. There is no HTTPS, and you need to add what your application needs here.
The app of app: 8090 is the Spring Boot container of docker-compose.yml described later.
Spring Boot
docker/docker-springboot/Dockerfile
FROM openjdk:10.0.1-jdk
RUN git clone https://github.com/xxxx/repo_name.git
WORKDIR ./repo_name
RUN ./gradlew --full-stacktrace -q build
CMD ./gradlew bootRun
docker/docker-springboot-local/Dockerfile
FROM openjdk:10.0.1-jdk
Since the necessary settings are specified from docker-compose.yml, the result is only FROM.
docker-compose.yml
version: '3'
services:
nginx:
container_name: container_nginx
build: docker/docker-nginx
restart: always
ports:
- 80:8080
hostname: container_nginx_hostname
links:
- app
app:
container_name: container_springboot
restart: always
build: docker/docker-springboot
expose:
- 8090
command: ./gradlew bootRun
hostname: container_springboot_hostname
#Used when launching quickly locally
# app:
# container_name: container_springboot-local
# restart: always
# build: docker/docker-springboot-local
# expose:
# - 8090
# command: ./gradlew bootRun
# hostname: container_springboot-local_hostname
# working_dir: /container_springboot
# volumes:
# - ./:/container_springboot
If you start it with docker-comose, you can execute the API on localhost / application path.
Since it was written roughly so as not to forget the contents of Dockerfile and docker-compose.yml, there is no detailed explanation, but I was able to accept the HTTP request with Nginx and send it to Spring Boot above.
Recommended Posts