반응형
Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- spring cloud
- cassandra
- jmeter
- weblogic 10
- vue.js
- JPA
- KAFKA
- Netty
- argo cd
- grafana
- Spring Open Feign
- Selenium
- Hibernate
- RabbitMQ
- WebLogic
- netflix oss
- mybatis
- Airflow
- docker compose mysql
- Docker Compose
- spring boot redis
- QueryDSL
- spring boot
- docker-compose
- MySQL
- ChannelPipeline
- docker
- coalesce
- Redis Sentinel
- redis
Archives
- Today
- Total
IT.FARMER
dockerfile에 springboot profile 적용하기 본문
반응형
dockerfile에 springboot profile 적용하기
docker file
ENV USE_PROFILE
을 환경설정 파일로 만들고 docker run 시에 설정 정보를 넣어서 실행할 수 있도록 한다. 디폴트 값은 local 이다.
# docker file
# 1. Start with a base image containing Java runtime
FROM adoptopenjdk/openjdk11
# 2. Add Author info
LABEL maintainer="skan@"
# Add a volume to /tmp
VOLUME /tmp
# Make port 8761 available to the world outside this container
EXPOSE 8761
# The application's jar file
ARG JAR_FILE=build/libs/spring-cloud-eureka-test-0.0.1-SNAPSHOT.jar
# Add the application's jar to the container
COPY ${JAR_FILE} spring-cloud-eureka.jar
ENV USE_PROFILE=local
# Run the jar file
ENTRYPOINT ["java","-Dspring.profiles.active=${USE_PROFILE}","-Djava.security.egd=file:/dev/./urandom","-jar","/spring-cloud-eureka.jar"]
docker build
docker build -t {image name}:{tag version} {docker file path}
docker build -t spring-cloud-eureka-server:latest ./
docker images
------
REPOSITORY TAG IMAGE ID CREATED SIZE
spring-cloud-eureka-server latest 702b2ed6b7ba 34 seconds ago 485MB
docker build option 설명
- t –tag: 레파지토리(이미지이름)과 테그명을 입력한다 ‘:’ 기준으로 {이미지이름}:{테그번호}로 남겨진다. 테그 번호를 남기지 않으면 자동으로 latest가 된다
- ./ : Dockerfile 이 있는 경로를 지정해 준다. (지금은 현재 디렉토라)
image 생성후 docker run 으로 container 생성
docker run -d -p 8761:8761 --name={container_name} {image_name}
docker run -d -p 8761:8761 --name=spring-discovery spring-cloud-eureka-server:latest
생성된 container 확인
docker build 로는 이미지를 생성하는 것이기 때문에 컨테이너에는 나타나지 않는다. docker run 으로 실행시킨 후 container 가 생성된 것을 확인 할 수 있다.
skan@mezzoui-MacBookPro spring-cloud-eureka-test % docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8f55b814771b spring-cloud-eureka-server:latest "java -Djava.securit…" 8 seconds ago Up 8 seconds 0.0.0.0:8761->8761/tcp, :::8761->8761/tcp spring-discovery
0efaf8cded3a jenkins_jenkins "/sbin/tini -- /usr/…" 59 minutes ago Up 59 minutes 0.0.0.0:50000->50000/tcp, :::50000->50000/tcp, 0.0.0.0:9090->8080/tcp, :::9090->8080/tcp jenkins
756f617f2699 mysql:5.7.21 "docker-entrypoint.s…" 5 weeks ago Up 6 hours 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp mysql
docker start 및 stop
docker run 으로 생성한 컨테이너들은 다시 run 으로 생성 할 수 없다. 컨테이너 아이디를 사용하여 서비스를 시작 혹은 중지한다.
docker start {container_id}
docker stop {container_id}
docker run , spring parameter 적용
docker 에서는 실행시 -e 옵션을 이용하여 ENV USE_PROFILE=local
로 등록된 env 의 항목에 파라미터 값을 전달 할 수 있다.
- -e USE_PROFILE={profile}
docker run -p 80:8080 -d --restart always -e USE_PROFILE={profile} --name={container_name} {image_name}
docker run -p 8761:8761 -d --restart always -e USE_PROFILE=prod --name=spring-discovery spring-cloud-eureka-server:latest
실행된 콘솔에 the following profiles are active: prod
로 바뀌어서 나온걸 확인 할 수 있다.
반응형
'devops > docker' 카테고리의 다른 글
docker env, arg 차이점 (1) | 2024.04.07 |
---|---|
도커 실행 권한문제 - dial unix /var/run/docker.sock: connect: permission denied (0) | 2023.04.17 |
docker-compose mysql 설정 및 sql init (0) | 2022.01.14 |
docker-compose jenkins (0) | 2022.01.14 |
docker-compose 옵션 기본 명령어 (0) | 2021.04.29 |