도커 | 3강. dockerfile (mac 맥 m1)

2023. 3. 31. 14:11·리눅스

https://heytech.tistory.com/33

 

[Mac/Linux] 터미널에서 파일 생성/편집/저장 방법

📚 목차 1. 파일 생성하기 2. 내용 작성 3. 저장 및 종료 4. 편집 및 저장 1. 파일 생성하기 1) 기본 명령어 cat > 파일명.확장자명 2) 메모장 생성 예시 cat > memo.txt 3) 파이썬 파일 생성 예시 cat > main.py

heytech.tistory.com

 

도커파일 실습1 - 자바를 설치하고 자바 파일을 생성해서 실행해보기

준비사항

  • course/docker/first 예제폴더를 생성하고 이동해주세요.
  • window에서 실습하고 있지만, 리눅스 환경이라고 생각하고 사용하는 편이 좋습니다.

docker 경로로 이동

 

1. 메모장 만들기

cat > 파일명.확장자명

-메모장 작성 예시

cat > memo.txt 

cat > Hello.java

2. 내용 작성

public class Hello { public static void main(String[] args) { System.out.println("hello world"); } }

ctrl + z 누르면 나가짐

 

3. 자바이미지 찾기

docker search openjdk

4. 도커파일생성

cat > dockerfile

5. 도커파일작성

FROM adoptopenjdk/openjdk11

COPY Hello.java /

RUN javac Hello.java

ENTRYPOINT ["java", "Hello"]

 

6. 도커파일을 빌드하여 이미지로 만들기

docker build -t <이미지명>:<태그> <빌드할도커파일위치>
docker build -t hellojava:latest .

. 은 현재 위치

7. 컨테이너 실행

docker run <옵션> <이미지:태그>
docker run --name first hellojava:latest

 

 

컨테이너 안에 살펴보기

 

또 에러뜸..미치겠다. 

Last login: Fri Mar 31 12:42:08 on console
kuromi@ui-MacBookAir ~ % cd desktop                              
kuromi@ui-MacBookAir desktop % cd Coding
kuromi@ui-MacBookAir Coding % cd course
kuromi@ui-MacBookAir course % cd docker
kuromi@ui-MacBookAir docker % cd first
kuromi@ui-MacBookAir first % docker run --name first hellojava:latest
docker: Cannot connect to the Docker daemon at unix:///Users/kuromi/.colima/default/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
kuromi@ui-MacBookAir first % docker login
Authenticating with existing credentials...
Login did not succeed, error: Cannot connect to the Docker daemon at unix:///Users/kuromi/.colima/default/docker.sock. Is the docker daemon running?
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username (songeuna): songeuna
Password: 
Login Succeeded

Logging in with your password grants your terminal complete access to your account. 
For better security, log in with a limited-privilege personal access token. Learn more at https://docs.docker.com/go/access-tokens/
kuromi@ui-MacBookAir first % docker run --name first hellojava:latest
docker: Cannot connect to the Docker daemon at unix:///Users/kuromi/.colima/default/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
kuromi@ui-MacBookAir first % brew install colima

==> Downloading https://formulae.brew.sh/api/formula.jws.json
######################################################################## 100.0%
==> Downloading https://formulae.brew.sh/api/cask.jws.json
######################################################################## 100.0%
Warning: colima 0.5.4 is already installed and up-to-date.
To reinstall 0.5.4, run:
  brew reinstall colima
kuromi@ui-MacBookAir first % colima start
INFO[0000] starting colima                              
INFO[0000] runtime: docker                              
INFO[0000] preparing network ...                         context=vm
INFO[0000] starting ...                                  context=vm
> Using the existing instance "colima"
> [hostagent] Starting QEMU (hint: to watch the boot progress, see "/Users/kuromi/.lima/colima/serial.log")
> SSH Local Port: 49575
> [hostagent] Waiting for the essential requirement 1 of 5: "ssh"

^C
kuromi@ui-MacBookAir first % docker ps -a
Cannot connect to the Docker daemon at unix:///Users/kuromi/.colima/default/docker.sock. Is the docker daemon running?
kuromi@ui-MacBookAir first % colima start
INFO[0000] starting colima                              
INFO[0000] runtime: docker                              
INFO[0000] preparing network ...                         context=vm
INFO[0000] starting ...                                  context=vm
INFO[0042] provisioning ...                              context=docker
INFO[0042] starting ...                                  context=docker
INFO[0048] done                                         
kuromi@ui-MacBookAir first % docker ps -a
CONTAINER ID   IMAGE              COMMAND                  CREATED        STATUS                      PORTS                                       NAMES
ae4082bdbc2a   gvenzl/oracle-xe   "container-entrypoin…"   3 months ago   Exited (255) 20 hours ago   0.0.0.0:1521->1521/tcp, :::1521->1521/tcp   modest_wilbur
d0f36bb36c42   gvenzl/oracle-xe   "container-entrypoin…"   4 months ago   Exited (255) 3 months ago   0.0.0.0:1521->1521/tcp, :::1521->1521/tcp   nifty_bohr
kuromi@ui-MacBookAir first % docker run --name first hellojava:latest
Unable to find image 'hellojava:latest' locally
docker: Error response from daemon: pull access denied for hellojava, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
See 'docker run --help'.
kuromi@ui-MacBookAir first % docker build -t hellojava:latest .
[+] Building 2.4s (9/9) FINISHED                                                
 => [internal] load build definition from Dockerfile                       0.0s
 => => transferring dockerfile: 36B                                        0.0s
 => [internal] load .dockerignore                                          0.0s
 => => transferring context: 2B                                            0.0s
 => [internal] load metadata for docker.io/adoptopenjdk/openjdk11:latest   2.0s
 => [auth] adoptopenjdk/openjdk11:pull token for registry-1.docker.io      0.0s
 => [internal] load build context                                          0.0s
 => => transferring context: 171B                                          0.0s
 => [1/3] FROM docker.io/adoptopenjdk/openjdk11@sha256:a12ead789cb591943d  0.0s
 => CACHED [2/3] COPY Hello.java /                                         0.0s
 => CACHED [3/3] RUN javac Hello.java                                      0.0s
 => exporting to image                                                     0.0s
 => => exporting layers                                                    0.0s
 => => writing image sha256:2e16e083b7c13acc9951e2d51a757859ecd85cd04000b  0.0s
 => => naming to docker.io/library/hellojava:latest                        0.0s
kuromi@ui-MacBookAir first % docker run --name first hellojava:latest
Mar 31, 2023 3:47:57 AM java.util.prefs.FileSystemPreferences$1 run
INFO: Created user preferences directory.
|  Welcome to JShell -- Version 11.0.18
|  For an introduction type: /help intro

jshell> %                                                                       kuromi@ui-MacBookAir first % docker run -d -p 80:80 docker/getting-started
Unable to find image 'docker/getting-started:latest' locally
latest: Pulling from docker/getting-started
c158987b0551: Pull complete 
1e35f6679fab: Pull complete 
cb9626c74200: Pull complete 
b6334b6ace34: Pull complete 
f1d1c9928c82: Pull complete 
9b6f639ec6ea: Pull complete 
ee68d3549ec8: Pull complete 
33e0cbbb4673: Pull complete 
4f7e34c2de10: Pull complete 
Digest: sha256:d79336f4812b6547a53e735480dde67f8f8f7071b414fbd9297609ffb989abc1
Status: Downloaded newer image for docker/getting-started:latest
fd317fb739a3112ed28951599f5f69eb97f5cb9ebe5f0b703cdde6d3b2dee3e8
kuromi@ui-MacBookAir first %

https://smallsharpsoftwaretools.com/tutorials/use-colima-to-run-docker-containers-on-macos/

'리눅스' 카테고리의 다른 글

AWS EC2 인스턴스 삭제  (0) 2023.04.04
배포 | AWS EC2에 war파일 배포하기  (0) 2023.04.02
ppk 키 -> pem 키로 변환, 서버 접속  (0) 2023.03.30
개발자가 알아야 하는 리눅스명령문  (0) 2023.03.30
PuTTy 설치 (mac 맥 m1)  (0) 2023.03.30
'리눅스' 카테고리의 다른 글
  • AWS EC2 인스턴스 삭제
  • 배포 | AWS EC2에 war파일 배포하기
  • ppk 키 -> pem 키로 변환, 서버 접속
  • 개발자가 알아야 하는 리눅스명령문
개발 공부
개발 공부
  • 개발 공부
    개발 공부
    개발 공부
  • 전체
    오늘
    어제
    • 전체보기 (163)
      • 프로젝트 (1)
      • JavaScript (46)
      • Node.js (3)
      • Next.js (5)
      • React (17)
      • NoSQL (0)
      • HTML,CSS (3)
      • CS (6)
      • Java (35)
      • Spring (6)
        • Spring의 정석 (1)
      • Spring boot (1)
      • MySQL (1)
      • 리눅스 (16)
      • JSP (9)
      • AWS (0)
      • git (2)
      • 알고리즘 (1)
      • ect (7)
      • Project (2)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    오블완
    Java
    자바의 정석
    Java의 정석
    티스토리챌린지
    자바
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
개발 공부
도커 | 3강. dockerfile (mac 맥 m1)
상단으로

티스토리툴바