IT/docker

Minikube 및 testContainer(Docker이용한 테스트) 세팅 feat_Docker Desktop 유료화

주현태 2022. 1. 19. 18:12
DockerDesktop의 유료화로 인한 대체제로 minikube를 사용하라는 말이 들린다. 
minikube는 로컬환경에서 kubernetes 클러스터를 실행하는 데 사용된다고 한다
그러나 컨테이너를 실행하는 데 사용할 수 있는 도커 데몬도 실행되기에 기존의 Docker Desktop을 대체할 수 있다고 한다.
 
# Install hyperkit and minikube
brew install hyperkit
brew install minikube

# Install Docker CLI
brew install docker
brew install docker-compose

# Start minikube
minikube start

# Tell Docker CLI to talk to minikube's VM
eval $(minikube docker-env)

# Save IP to a hostname
echo "`minikube ip` docker.local" | sudo tee -a /etc/hosts > /dev/null

# Test
docker run hello-world

위와 같이 미니큐브 설치 및 docker-cli가 제대로 동작하는것을 확인하고, 이제 Java테스트용 라이브러리인 

 

testContainer를 돌리면 되겠거니 하여 코드를 돌리니 에러가 떨어진다.. ㅠ 

 

Can't get Docker image: RemoteDockerImage(imageName=docker.elastic.co/elasticsearch/elasticsearch:7.14.2, imagePullPolicy=DefaultPullPolicy())
org.testcontainers.containers.ContainerFetchException: Can't get Docker image: RemoteDockerImage(imageName=docker.elastic.co/elasticsearch/elasticsearch:7.14.2, imagePullPolicy=DefaultPullPolicy())
    at org.testcontainers.containers.GenericContainer.getDockerImageName(GenericContainer.java:1326)
    at org.testcontainers.containers.GenericContainer.logger(GenericContainer.java:643)
    at org.testcontainers.elasticsearch.ElasticsearchContainer.<init>(ElasticsearchContainer.java:73)
    at org.testcontainers.elasticsearch.ElasticsearchContainer.<init>(ElasticsearchContainer.java:57)
    at com.wmp.ep.index.manager.service.IndexManageServiceTest.beforeClass(IndexManageServiceTest.java:40)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:688)
    at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
    at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptLifecycleMethod(TimeoutExtension.java:126)
    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptBeforeAllMethod(TimeoutExtension.java:68)
    at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeBeforeAllMethods$9(ClassBasedTestDescriptor.java:384)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeBeforeAllMethods(ClassBasedTestDescriptor.java:382)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:196)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:78)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:136)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)

아무리 찾아보아도 해답을 찾을수 없어 StackOverflow에 물어보기로 하였다. 

 

 

https://stackoverflow.com/questions/70749679/how-can-i-use-testcontainer-in-mac-os-with-out-docker-desktop

 

How can i use testcontainer in mac os with out Docker Desktop?

Today, i heard new that the docker desktop will be not free. so, our team has conclusion to delete docker desktop and use minikube. then, we can use docker cli, but,, when we use testContainer in j...

stackoverflow.com

 

답변이 하루인가 이틀만에 달렸는데, 다음의 명령어를 수행하라고 한다.

$ eval $(minikube -p minikube docker-env)
$ echo "docker.host=$DOCKER_HOST" >> ~/.testcontainers.properties
$ echo "docker.cert.path=$DOCKER_CERT_PATH" >> ~/.testcontainers.properties
$ echo "docker.tls.verify=true" >> ~/.testcontainers.properties

이렇게 하고 testContainer를 수행하니까 아래와 같은 결과가 나왔다.

너무 잘되어서 따봉 과 답변체크를 눌러주고 이슈를 완료처리 하였다.

 

정말 행복하다