키페어 소유자만이 접근할 수 있도록 권한 설정
chmod 400 photo-app-api-keypair.pem
EC2 연결
ssh -i "photo-app-api-keypair.pem" ec2-user@ec2-15-164-49-140.ap-northeast-2.compute.amazonaws.com
sudo yum install docker
sudo service docker start
sudo usermod -a -G docker ec2-user
Note
sudo usermod -a -G docker ec2-user
사용 후에 exit
을 치고 다시 접속하면 sudo
를 치면서 Docker를 사용하지 않아도 됩니다.RabbitMQ 실행
docker run -d --name photoapp-rabbitmq -p 15672:15672 -p 5672:5672 -p 15671:15671 -p 5671:5671 -p 4369:4369 rabbitmq:3-management
Note
Dockerfile 생성
FROM openjdk:8-jdk-alpine
VOLUME /tmp
COPY UnlimitedJCEPolicyJDK8/* /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/
COPY target/PhotoAppApiConfigServer-0.0.1-SNAPSHOT.jar ConfigServer.jar
ENTRYPOINT ["java", "-jar", "ConfigServer.jar"]
Docker image 생성
docker build --tag=config-server --force-rm=true .
생성한 Docker image 태그 추가
docker tag {image.id} dnjscksdn98/config-server
DockerHub로 push
docker push dnjscksdn98/config-server
RabbitMQ IP 주소 검색
docker inspect {rabbitmq.id}
Run Config Server from DockerHub
docker run -d -p 8012:8012 -e "spring.rabbitmq.host={ip.address}" dnjscksdn98/config-server
Note
Dockerfile 생성
FROM openjdk:8-jdk-alpine
COPY target/PhotoAppDiscoveryService-0.0.1-SNAPSHOT.jar DiscoveryService.jar
ENTRYPOINT ["java", "-jar", "DiscoveryService.jar"]
Docker image 생성
docker build --tag=config-server --force-rm=true .
생성한 Docker image 태그 추가
docker tag {image.id} dnjscksdn98/config-server
DockerHub로 push
docker push dnjscksdn98/config-server
Run Eureka Server from DockerHub and override config server uri
docker run -d -p 8010:8010 -e "spring.cloud.config.uri=http://{configServer.privateIP}:8012" dnjscksdn98/eureka-server
Dockerfile 생성
FROM openjdk:8-jdk-alpine
VOLUME /tmp
COPY target/PhotoAppZuulApiGateway-0.0.1-SNAPSHOT.jar ZuulApiGateway.jar
ENTRYPOINT ["java", "-jar", "ZuulApiGateway.jar"]
Docker image 생성
docker build --tag=config-server --force-rm=true .
생성한 Docker image 태그 추가
docker tag {image.id} dnjscksdn98/config-server
DockerHub로 push
docker push dnjscksdn98/config-server
docker run -e "spring.cloud.config.uri=http://{configServer.privateIP}:8012" -e "spring.rabbitmq.host={RabbitMQ.IP}" -p 8011:8011 -d dnjscksdn98/zuul-api-gateway
docker run -d \
> -e "spring.cloud.config.uri=http://{configServer.privateIP}:8012" \
> -e "logging.file=/api-logs/albums-ws.log" \
> -v /home/ec2-user/api-logs:/api-logs \
> -e "server.port=8989" \
> -p 8989:8989 \
> dnjscksdn98/albums-microservice
docker run -d \
> -p 3306:3306 \
> --name mysql-container \
> -e MYSQL_ROOT_PASSWORD=alex \
> -e MYSQL_DATABASE=photo_app \
> -e MYSQL_USER=alex \
> -e MYSQL_PASSWORD=alex \
> -v /var/lib/mysql:/var/lib/myslq \
> mysql:latest
-v /var/lib/mysql:/var/lib/myslq