티스토리 뷰

반응형

위 내용은 Docker Training 사이트의 강의 내용을 토대로 실습한 내용을 정리한 글입니다.

원본 사이트 : https://training.docker.com/docker-fundamentals


도커 소개

간단한 명령어

docker run
docker ps
docker images

목차(Agenda)

  • Building Images
  • Dockerfile
  • Managing Images and Containers
  • Distributing Images on Docker Hub
  • Docker Volumes
  • Basic Container networking
  • Docker in continuous integration

Building Images

Image Layer

  • Images are comprised of multiple layers(이미지는 여러 레이어로 구성됩니다.)
  • A layer is also just another image(레이어는 또 다른 이미지이기도합니다.)
  • Every image contains a base layer(모든 이미지에는 기본 레이어가 포함되어 있습니다.)
  • Docker uses a copy on write system(Docker는 쓰기 시스템에서 사본을 사용합니다.)
  • Layers are read only(레이어는 읽기 전용입니다.)

The container Writable Layer

  • Docker creates a top writable layer for containers(Docker는 컨테이너에 대한 쓰기 가능한 최상위 레이어를 만듭니다.)
  • Parent images are read only(부모 이미지는 읽기 전용입니다.)
  • All changes are made at the writeable layer(모든 변경은 쓰기 가능한 레이어에서 이루어집니다.)

Docker Commit

  • Docker commit command saves changes in a container as a new image(Docker commit 명령은 컨테이너의 변경 사항을 새 이미지로 저장합니다.)
  • Syntax docker commit [options] [container ID] [repository:tag]
  • Repository name should be based on username/application(저장소 이름은 사용자 이름/응용 프로그램을 기반으로 해야합니다.)
  • Can reference the container with container name instead of ID(ID 대신 컨테이너 이름으로 컨테이너를 참조 할 수 있습니다.)

Bulid new Image

기본 우분투 이미지를 찾기

docker search ubuntu

이미지 다운로드

docker pull ubuntu

이미지에 접속하여 실행

docker run -it ubuntu

이미지 실행 후 우분투 내용 업데이트

url이 우분투에 설치 되어 있지 않은 상태

상태 확인 후 apt-get 업데이트 후 curl install

root@4b786ef4aa9e:/# curl
bash: curl: command not found
root@4b786ef4aa9e:/# apt-get update
root@4b786ef4aa9e:/# apt-get install curl

도커 이미지 실행 확인

docker ps -a

컨테이너 ID 확인(현재 - 4b786ef4aa9e)

새로운 도커 이미지 생성(우분투 + curl)

docker commit 4b786ef4aa9e softmagic/curl:1.0

생성된 도커 이미지 확인 및 접속

docker run -it softmagic/curl:1.0

Summary

#이미지 실행(이미지명, 버전 정보기 latest가 아닌 경우 버전 정보 필수)
docker run -it ubuntu 
#실행된 이미지에 프로그램 설치
apt-get update
apt-get install -y curl
#컨테이너 나가기
exit
#설치 되었던 컨테이너 ID 확인
docker ps -a
#이미지 저장
docker commit <컨테이너 ID> <이름>/curl:1.0
#저장된 이미지로 접속
docker run -it 이름/curl:1.0

Dockerfile

Intro to Dockerfile

A Dockerfile is a configuration file that contains instructions for building a Docker image(Dockerfile은 Docker 이미지를 작성하기 위한 지침이 포함된 구성 파일입니다.)

  • Provides a more effective way to build images compared to using docker commit(도커 커밋 (docker commit)을 사용하는 것보다 이미지를 빌드하는 효과적인 방법을 제공합니다.)
  • Easily fits into your continuous integration and deployment process(지속적인 통합 및 배포 프로세스에 쉽게 적용됩니다.)

Dckerfile instructions

  • Instructions specify what to do when building the image(지침은 이미지를 만들 때 수행할 작업을 지정합니다.)
  • FROM instruction specifies what the base image should be(FROM 명령은 기본 이미지가 무엇인지 지정합니다.)
  • RUN instruction specifies a command to execute(RUN 명령은 실행할 명령을 지정합니다.)

Run Instruction

  • Each RUN instruction will execute the command on the top writable layer and perform a commit of the image(Each RUN 명령은 쓰기 가능한 최상위 레이어에서 명령을 실행하고 이미지 커밋을 수행합니다.)
  • Can aggregate multiple RUN instructions by using "&&"("&&"를 사용하여 여러 RUN 명령어를 실행할 수 있습니다.)

Docker Build

  • Syntax docker build [options] [path] <== build context(빌드 컨텍스트)
  • Common option to tag the build(빌드에 태그를 지정하는 일반적인 옵션) : docker build -t [repository:tag] [path]

도커파일 테스트

mkdir test
cd test
sudo atom Dockerfile

Dockerfile

FROM ubuntu:14.04
RUN apt-get update
RUN apt-get install -y curl
RUN apt-get install -y vim

도커 파일 실행

docker build -t <Docker Hub ID>/testimage:1.0 .

도커파일(명령어 정렬)

FROM ubuntu
RUN apt-get update && apt-get install -y curl \
                                                           vim

CMD Instruction

  • CMD defines a default command to execute when a container is created(cmd는 컨테이너가 생성될 때 실행할 기본 명령을 정의합니다.)
  • CMD performs no action during the image build(CMD는 이미지를 빌드하는 동안 아무런 작업도 수행하지 않습니다.)
  • Shell format and EXEC format(셸 형식 및 EXEC 형식)
  • Can only be specified once in a Dockerfile(Dockerfile에서만 한 번만 지정할 수 있습니다.)
  • Can be overridden at run time(런타임에 재정의 될 수 있습니다.)

아톰으로 Dockerfile을 열어 내용 수정(ping)

sudo atom Dockerfile

Dockerfile

FROM ubuntu:14.04
RUN apt-get update && apt-get install -y curl \
                                         vim
CMD ["ping", "127.0.0.1", "-c", "10"]

Dockerfile 빌드

docker build -t <Docker Hub ID>/testimage:1.1 .

도커 이미지 실행

docker run <Docker Hub ID>/testimage:1.1
docker run <Docker Hub ID>/testimage:1.1 echo "hello world"

echo "hello world" 명령을 같이 쓰면 기존의 CMD는 무시하고 오버라이드.

ENTRYPOINT Instruction(명령어를 실행)

  • Defines the command that will run when a container is executed(컨테이너가 실행될 때 실행할 명령을 정의합니다.)
  • Run time arguments and CMD instruction are passed as parameters to the ENTRYPOINT instruction(런타임 인수 및 CMD 명령은 매개 변수로 ENTRYPOINT 명령에 전달됩니다.)
  • Shell and EXEC form(쉘 및 EXEC 형식)
  • EXEC form preferred as shell form cannot accept arguments at run time(셸 형식으로 기본 설정된 EXEC 형식은 런타임에 인수를 받아 들일 수 없습니다.)
  • Container essentially runs as an executable(컨테이너는 기본적으로 실행 파일로 실행됩니다.)

아톰으로 Dockerfile을 열어 내용 수정(ping)

sudo atom Dockerfile

Dockerfile

FROM ubuntu:14.04
RUN apt-get update && apt-get install -y curl \
                                         vim
ENTRYPOINT ["ping"]

Dockerfile 빌드

docker build -t <Docker Hub ID>/testimage:1.2 .

도커 이미지 실행

docker run <Docker Hub ID>/testimage:1.2 127.0.0.1 -c 5


Managing Images and Containers

Start and Stop Containers

  • Find your containers first with docker ps and note the ID or name(docker ps로 컨테이너를 먼저 찾은 다음 ID 또는 이름을 기록합니다.)
  • docker start and docker stop

docker run -d nginx
#컨테이너 ID 확인
docker ps
#컨테이너 중지
docker stop <컨테이너ID>
#중지된 컨테이너 확인
docker ps -a
#컨테이너 시작
docker start <중지된 컨테이너 이름 또는 ID>

nginx 실행 , 받은 이미지가 없으면 최신 버전으로 받은 후 실행


Getting terminal access

  • Use docker exec command to start another process within a container(docker exec 명령을 사용하여 컨테이너 내에서 다른 프로세스를 시작하십시오.)
  • Execute /bin/bash to get a bash shell(/bin/bash를 실행하여 bash 쉘을 얻으십시오.)
  • docker exec -i -t [container ID] /bin/bash
  • Exiting from the terminal will not terminate the container(터미널을 종료하면 컨테이너가 종료되지 않습니다.)
docker run -d tomcat:7
#컨테이너ID 확인
docker ps
docker exec -it [container ID] bash

root@b33dd7f3d690:/usr/local/tomcat# cd
root@b33dd7f3d690:~# ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  4 06:14 ?        00:00:03 /docker-java-home/jre/bin/java -Djava.util.logging.co
root        58     0  0 06:15 pts/0    00:00:00 bash
root        64    58  0 06:15 pts/0    00:00:00 ps -ef
root@b33dd7f3d690:~# exit

PID 1번은 java가 실행중임

exit 명령을 실행할 때 bash의 PID가 1번이 아니기 때문에 컨테이너가 종료되진 않음.

Deleting Containers

  • Can only delete containers that have been stopped(중지 된 컨테이너만 삭제할 수 있습니다.)
  • Use docker rm command(docker rm 명령 사용)
  • Specify the container ID or name(컨테이너 ID 또는 이름 지정)
docker ps
docker stop [컨테이너 이름/ID]
docker ps -a
docker rm [컨테이너 이름/ID]

Deleting local Images

  • Use docker rmi command(docker rmi 명령 사용)
  • docker rmi [image ID] or docker rmi [repo:tag]
  • if an image is tagged multiple times, remove each tag(이미지에 여러 번 태그가 지정되면 각 태그를 제거하십시오.)


Docker Hub Repositories

  • Users can create their own repositories on Docker Hub(사용자는 Docker Hub에서 자체 저장소를 만들 수 있습니다.)
  • Public and Private(공개 및 비공개)
  • Push local images to a repository(로컬 이미지를 저장소로 푸시합니다.)

https://hub.docker.com/


Pushing Images to Docker Hub

  • Use docker push command(docker push 명령 사용)
  • Syntax docker push [repo:tag]
  • Local repo must have same name and tag as then Docker Hub repo(로컬 저장소는 Docker 허브 저장소와 동일한 이름과 태그를 가져야합니다.)

Tagging Images

  • Use to rename a local image repository before pushing to Docker Hub(Docker 허브로 푸시하기 전에 로컬 이미지 저장소의 이름을 바꾸는 데 사용합니다.)
  • Syntax: docker tag [image ID] [repo:tag] OR docker tag [local repo:tag] [Docker Hub repo:tag]

개발 서버로 PUSH

tagging(개발 서버 도커 이미지 등록시 아이피 로 태킹 )


Docker Hub로 PUSH

#로컬 이미지 저장소의 이름을 Docker Hub 저장소와 동일하게 변경 docker tag <로컬 이미지 저장소 이름>/testimage:1.0 <Docker Hub ID>/testimage:1.0 #Docker Hub 계정에 로그인 docker login #tagging한 이미지를 Docker Hub에 Push docker push <Docker Hub ID>/testimage:1.0

[denied Error 해결 방법]

denied: requested access to the resource is denied

login 명령을 통해 Docker Hub에 로그인한 뒤 push 명령을 실행합니다.

docker login

Push to Docker Hub

  • Login to your Docker Hub account(Docker 허브 계정에 로그인하십시오.)
  • Create a new public repository called "testexample"("testexample"이라는 새로운 공용 저장소를 만듭니다.)
  • Tag your local image to give it the same repo name as the repository you created on Docker Hub docker tag <yourname>/testimage:1.1 <yourname>/testexample:1.1(Docker Hub 도커 태그 <yourname> /testimage:1.1 <yourname> /testexample:1.1에서 만든 리포지토리와 동일한 저장소 이름을 지정하기 위해 로컬 이미지에 태그를 지정하십시오.)
  • Push the new image to Docker Hub docker push <yourname>/testexample:1.1(새 이미지를 Docker 허브 도커 푸시 <yourname> /testexample:1.1에 푸시합니다.)
  • Go to your Docker repository and check for the tag(Docker 저장소로 이동하여 태그를 확인하십시오.)

Volumes

A Volume is a designated directory in a container, which is designed to persist data, independent of the container's life cycle.(볼륨은 컨테이너의 지정된 디렉토리이며 컨테이너의 수명주기와 관계없이 데이터를 유지하도록 설계되었습니다.)

  • Volume changes are excluded when updating an image(이미지를 업데이트 할 때 볼륨 변경이 제외됩니다.)
  • Persist when a container is deleted(컨테이너가 삭제 될 때 지속됩니다.)
  • Can be mapped to a host folder(호스트 폴더에 매핑 가능)
  • Can be shared between containers(컨테이너 간에 공유 가능)

Mount a Volume

  • Volumes are mounted when creating or executing a container(컨테이너를 만들거나 실행할 때 볼륨이 마운트됩니다.)
  • Can be mapped to a host directory(호스트 디렉토리에 매핑 가능)
  • Volume paths specified must be absolute(지정된 볼륨 경로는 절대 경로여야합니다.)

Volumes in Dockerfile

  • VOLUME instruction creates a mount point(VOLUME 명령으로 마운트 지점을 만듭니다.)
  • Can specify arguments JSON array or string(JSON 배열 또는 문자열 인수를 지정할 수 있습니다.)
  • Cannot map volumes to host directories(호스트 디렉토리에 볼륨을 맵핑할 수 없습니다.)
  • Volumes are initialized when the container is executed(컨테이너가 실행될 때 볼륨이 초기화됩니다.)

Uses of volumes

  • De-couple the data that is stored from the container which created the data(데이터를 생성한 컨테이너에서 저장된 데이터의 연결을 끊습니다.)
  • Good for sharing data between containers Can setup a data containers which has a volume you mount in other containers(컨테이너간에 데이터를 공유하는 데 적합합니다. 다른 컨테이너에 마운트 한 볼륨이 있는 데이터 컨테이너를 설정할 수 있습니까?)
  • Mounting folders from the host is good for testing purposes but generally not recommended for production use(호스트에서 폴더를 마운트하는 것은 테스트 목적으로 적합하지만 프로덕션 용도로는 일반적으로 권장되지 않습니다.)

도커를 중지하면 도커이미지에 생성된 파일은 없어짐

docker run -d -P -v /www/website nginx

docker exec -it [컨테이터 ID] bash
ls 
cd www/website/
echo "hello" >> test
ls
cat test
exit

docker stop [컨테이너 ID]
docker commit [컨테이너 ID] test:1.0
docker run -it test:1.0 bash
ls 
cd www/website/
ls
exit

[Error Message]

rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:1370: sending signal 0 to pid 3703 caused "permission denied"

--> Ubuntu 재설치...

Create and test a Volume

  • Execute a new container and initialise a volume at /www/website. Run a bash terminal as your container process(새 컨테이너를 실행하고 / www / website에서 볼륨을 초기화하십시오. bash 터미널을 컨테이너 프로세스로 실행하십시오.) : docker run -i -t -v /www/website ubuntu:14.04 bash
  • Inside the container, verify that you can get to /www/website(컨테이너 내부에서 /www/website에 도착할 수 있는지 확인하십시오.)
  • Create a file inside the /www/website folder(/www/website 폴더 안에 파일 만들기)
  • Exit the container(컨테이너에서 나가기)
  • Commit the updated container as a new image called test and tag it as 1.0(업데이트된 컨테이너를 test라는 새 이미지로 커밋하고 1.0으로 태그 지정합니다.) : docker commit <container ID> test:1.0
  • Execute a new container with your test image and go into it's bash shell(테스트 이미지로 새 컨테이너를 실행하고 bash 쉘로 들어가십시오.) : docker run -i -t test:1.0 bash
  • Verify that the /www/website folder exists and that there are no files inside(/www/website 폴더가 있고 그 안에 파일이 없는지 확인하십시오.)

Container Networking Basics

Mapping ports

  • Recall: containers have theit own network and IP address(리콜 : 컨테이너에는 자체 네트워크와 IP 주소가 있습니다.)
  • Map exposed container ports to ports on the host machine(노출된 컨테이너 포트를 호스트 시스템의 포트에 매핑)
  • Ports can be manually mapped or auto mapped(포트는 수동으로 매핑하거나 자동 매핑 할 수 있습니다.)
  • Uses the -p and -P parameters in docker run(docker run에서 -p 및 -P 매개 변수를 사용합니다.)

도커 컨테이너의 외부에서 사용할 포트와 내부에서 사용하는 포트 연결

내부 nginx에서 80 를 사용해서 외부의 시스템 8080 포트로 연결

hyper@hyper-ledger:~$ docker run -d -p 8080:80 nginx
5f1161e3c6c8802e09811668954ec35afce730c7c4f9cd63424ff42e83c9ab16
hyper@hyper-ledger:~$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
5f1161e3c6c8        nginx               "nginx -g 'daemon ..."   10 seconds ago      Up 8 seconds        0.0.0.0:8080->80/tcp   unruffled_davinci
hyper@hyper-ledger:~$



Automapping port

  • Use the -P option in docker run(도커 실행시 -P 옵션 사용)
  • Automatically maps exposed ports in the container to a port number in the host(컨테이너의 노출된 포트를 호스트의 포트 번호에 자동 매핑합니다.)
  • Host port numbers used go from 49153 to 65535(사용된 호스트 포트 번호는 49153에서 65535 사이입니다.)
  • Only works for ports defined in the EXPOSE instruction(EXPOSE 명령에 정의된 포트에 대해서만 작동합니다.)

오토맵핑으로 49153~65535 번 포트를 사용해서 자동 연결

EXPOSE instruction

  • Configures which ports a container will listen on at runtime(컨테이너가 런타임에 수신 대기하는 포트를 구성합니다.)
  • Ports still need to be mapped when container is executed(컨테이너가 실행될 때 포트를 매핑해야합니다.)

Linking Containers

Linking is a communication method between containers which allows them to securely transfer data from one to another(연결은 컨테이너간에 데이터를 안전하게 전송할 수있는 컨테이너 간의 통신 방법입니다.)

  • Secure and recipient containers(보안 컨테이너 및 수신자 컨테이너)
  • Recipient containers have access to data on source containers(수신자의 컨테이너는 원본 컨테이너의 데이터에 액세스 할 수 있습니다.)
  • Links are established based on container names(컨테이너 이름을 기반으로 링크가 설정됩니다.)

  1. Create the source container first(소스 컨테이너를 먼저 작성하십시오.)
  2. create the recipient container and use the --link option(받는 사람 컨테이너를 만들고 --link option을 사용하십시오.)
  • Best practice - give your containers meaningful names(우수 사례 - 컨테이너에 의미있는 이름을 지정하십시오.)

소스 컨테이를 먼저 생성하고 다음 링크를 통해서 소스컨테이를 참조하는 컨테이너를 생성

--> --link database:db db는 alias

#도커 상태 확인
docker ps
#실행중인 컨테이너가 있을 때는 모두 종료
docker rm $(docker ps -aq) -f

#'dbms'라는 이름으로 postgres 컨테이너 실행
docker run -d --name dbms postgres
docker ps

#'website'라는 이름으로 ubuntu 이미지를 사용하여 bash 실행(dbms 컨테이너와 연결. 별칭은 db)
docker run -it --name website --link dbms:db ubuntu:14.04 bash
#생성된 db entry 확인
cat /etc/hosts
exit

#IP주소는 dbms 컨테이너에 저장됨
docker inspect dbms | grep IPAddress

Uses of Linking

  • Containers can talk to each other without having to expose ports to the host(컨테이너는 호스트에 포트를 노출하지 않고도 서로 대화할 수 있습니다.)
  • Essential for micro service application architecture(마이크로 서비스 응용 프로그램 아키텍처에 필수적입니다.)
  • Example:
    • Container with Tomcat running(Tomcat이 실행중인 컨테이너)
    • Container with MySQL running(MySQL이 실행중인 컨테이너)
    • Application on Tomcat needs to connect to MySQL(Tomcat의 응용 프로그램이 MySQL에 연결해야합니다.) - MySQL이 원본 컨테이너, Tomcat이 수신자 컨테이너
  1. un a container in detached mode using the postgres image.Name the containder "dbms"(postgres 이미지를 사용하여 분리 모드로 컨테이너를 실행하십시오. 컨테이너 "dbms"의 이름을 지정하십시오.) : dockerrun -d --name dbms postgres
  2. Run another container using the Ubuntu image and link it with the "dbms" container. Use the alias "db", run the bash terminal as the main process(Ubuntu 이미지를 사용하여 다른 컨테이너를 실행하고 "dbms"컨테이너와 연결하십시오. 별칭 "db"를 사용하여 bash 터미널을 주 프로세스로 실행하십시오.) : docker run -it --name website --link dbms:db ubuntu:14.04 bash
  3. In the "website" container terminal, open the /etc/hosts file("웹 사이트"컨테이너 터미널에서 /etc/hosts 파일을 엽니다.)
  4. What can you observe?(무엇을 관찰할 수 있습니까?)

Docker in Continuous Integration

Traditional Continuous Integration

전통적인 개발 배포

Using Docker in CI[1]

  • CI server builds Docker image and pushes into Docker Hub(CI 서버는 Docker 이미지를 작성하고 Docker Hub에 푸시합니다.)

Docker Hub Auto Build

  • Docker Hub detects commits to source repository and builds the image(Docker Hub는 소스 저장소에 대한 커밋을 감지하고 이미지를 빌드합니다.)
  • Container is run during image build(이미지 빌드 중에 컨테이너가 실행됩니다.)
  • Testing done inside container(컨테이너 내부 테스트 완료)

소스 커밋 --> 도커 허브 빌드 --> 이미지 다운로드 및 실행

  1. CI (Continuous Integration)  지속적 통합이라는 뜻으로 형상관리 시스템 (SVN or Git) 에 있는 Source 파일을 읽어들여 자동으로 빌드하여 실행할 수 있는 결과물 형태 (exe , jar, apk or war 등) 로 주기적으로 생산해주는 시스템 그냥 쉽게 말하면 주기적으로 소스파일을 빌드해서 실행 파일을 만든다.(젠킨스 - Jenkins)

Eexample - Simple Java Application

"Hello World"를 출력하는 프로그램

cd ~/test
mkdir javahelloworld
cd javahelloworld

sudo atom JavaHelloWorld.java

sudo atom Dockerfile

JavaHelloWorld.java

public class JavaHelloWorld
{
  public static void main (String [] args)
  {
    System.out.println("Java Hello World");
    System.out.println("Hello again");
  }
}

Dockerfile

FROM java:7
COPY JavaHelloWorld.java
RUN javac JavaHelloWorld.java

CMD ["java", "JavaHelloWorld"]

GitHub

https://github.com/

SSH Key 등록

GitHub 계정에 로그인한 뒤 화면 오른쪽 상단의 메뉴 버튼을 클릭한 뒤 'Settings -> SSH and GPG keys' 메뉴에 들어갑니다.

'New SSH key' 버튼을 클릭합니다.

GitKraken에서 발급한 사용자의 SSH Public Key 값을 복사해 입력하고 'Add SSH key' 버튼을 클릭합니다.

다음과 같은 화면이 출력되면 SSH key가 정상적으로 등록된 것입니다.

New repository 생성

GitHub의 메인 화면에서 'New repository' 버튼을 클릭합니다.

'javahelloworld'라는 이름의 새로운 프로젝트를 생성합니다.

git 연결

smartgit을 통해 remote를 연결해줍니다.

smartgit

'Repository -> Add or Create' 메뉴를 클릭해 새로운 저장소를 추가합니다.

Repository는 '~/test/javahelloworld'로 설정합니다.

그런 다음 'Remote -> Push To' 메뉴를 클릭합니다.

Push To 알림창이 나오면 'Add Remote' 버튼을 클릭합니다.

그러면 'Add Remote Repository' 창이 뜨게 됩니다. 'URL or Path' 값에는 gitlab에서 생성한 javahelloworld 프로젝트의 SSH URL을 복사해 입력합니다.

ssh server vertification 창이 뜨면 'Accept' 버튼을 클릭합니다.

'SSH Authentication' 창이 뜨면 자신의 Private Key File을 넣고 Login 합니다.

연결이 완료되면 생성한 Dockerfile과 JavaHelloWorld.java 파일을 선택하고 Commit 버튼을 누릅니다

Commit이 완료되면 Push 버튼을 클릭해 gitlab의 javehelloworld 프로젝트에 소스를 push합니다.

이제 javahelloworld 저장소에 소스가 추가된 것을 확인할 수 있습니다.

Docker Hub

https://hub.docker.com/

Docker Hub에 로그인한 뒤 오른쪽 상단의 'Create -> Create Automated Build'를 클릭해 GitHub 계정과 연결시켜줍니다.

연결된 GitHub이 없는 경우 'Link Accounts' 버튼을 클릭해 사용자의 GitHub 계정과 연결시켜 줍니다.

'Linked Accounts & Services' 화면에서 'Link Github'를 선택합니다.

'Connet to GitHub' 화면에서 'Public and Private (Recommended)'을 선택합니다.

'Authorize docker' 버튼을 클릭해 사용자의 Docker Hub Registry와 GitHub를 연결합니다.

Create Auto-build

GitHub 계정과의 연결이 완료되면 이제 다시 오른쪽 상단의 'Create -> Create Automated Build'를 클릭합니다.

'Create Auto-build' 버튼을 클릭합니다.

GitHub에 생성한 'javahelloworld' 저장소를 선택합니다.

'javahelloworld'라는 이름으로 Docker Hub에 새로운 public 저장소를 추가합니다. 화면 하단의 'By default Automated Builds will match branch names to Docker build tags. Click here to customize behavior.'를 클릭해 master라는 이름에 latest 태그를 추가합니다.

'Create' 버튼을 클릭하면 새로운 저장소 생성이 완료되고 다음과 같은 화면이 출력됩니다.

'Tag' 탭을 클릭하면 latest 태그를 확인할 수 있습니다.

이미지 실행

DockerHub에 생성한 이미지를 받아와서 실행하면 다음과 같은 결과가 출력됩니다.

docker pull <Docker Hub ID>/javahelloworld
docker run <Docker Hub ID>/javahelloworld

Automated Build Test

소스를 수정하고 commit & push를 하면 수정된 내용의 소스가 자동으로 빌드됩니다.

java 파일 수정

JavaHelloWorld.java 파일을 다음과 같이 수정하고 GitHub 저장소에 Commit & Push 합니다.

public class JavaHelloWorld
{
  public static void main (String [] args)
  {
    System.out.println("Java Hello World");
    System.out.println("Hello again");
    System.out.println("Hello again and again");
  }
}
Docker Hub 확인

Docker Hub에서 'Build Details' 탭을 클릭하면 다음과 같이 수정된 내용이 자동으로 빌드된 것을 확인할 수 있습니다.

리스트를 클릭하면 Dockerfile과 Logs를 확인할 수 있습니다.

이미지 재실행

이미지를 다시 받아온 뒤 실행하면 수정된 내용이 적용되어 실행되는 것을 확인할 수 있습니다.

docker pull <Docker Hub ID>/javahelloworld
docker run <Docker Hub ID>/javahelloworld


반응형
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
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
글 보관함