Docker Hub에 내 이미지 업로드하기

Docker Hub에 내 이미지 업로드하기

화면에 "Hello Kubernetes"를 출력해주는 Node.js 파일이 있다.

[root@centos7 kube]# cat hello.js var http = require('http'); var content = function(req, resp) { resp.end("Hello Kubernetes!" + "

"); resp.writeHead(200); } var w = http.createServer(content); w.listen(8000);

이 파일을 Docker 이미지로 만든 후 Docker Hub에 업로드해보려 한다.

과정은 아래와 같다.

1. Dockerfile로 컨테이너 만들기

Dockerfile

FROM node:slim EXPOSE 8000 COPY hello.js . CMD node hello.js

- 현재 centos7에는 nodejs가 설치돼있지 않지만 docker hub에서 node:slim이란 파일을 가져옴으로써

js 파일이 출력 가능한 컨테이너가 만들어진다.

< 출처 : docker hub >

2. Dockerfile을 기반으로 이미지 빌드하기

- wowjd1375의 경우 Repository ID이고 뒤에 붙은 hello는 이미지명이다.

원래 hello:[버전] 정보가 붙지만 비어있는 경우 latest로 생성된다.

- 마지막엔 Dockerfile의 경로를 적어준다.

[root@centos7 kube]# docker build -t wowjd1375/hello . ... ... Successfully built 0d96335faf3a

생성된 이미지를 확인한다.

[root@centos7 kube]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE wowjd1375/hello latest 0d96335faf3a 28 minutes ago 176 MB

3. docker hub에 로그인한 후 이미지를 업로드해준다.

- 여기서 주의할 점은 이미지 생성 시 지정했던 Repository와 Docker hub의 ID가 일치해야 한다.

일치하지 않은 경우 docker push 시 denied: requested access to the resource is denied 에러가 발생한다.

[root@centos7 kube]# docker login 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 (wowjd1375): wowjd1375 Password: Login Succeeded

- docker push 명령어를 통해 생성했던 Image를 업로드해준다.

[root@centos7 kube]# docker push wowjd1375/hello The push refers to a repository [docker.io/wowjd1375/hello] dc753acdf6eb: Pushed 69634ad4b9b3: Pushed ...

- 업로드 후에는 docker hub에 로그인해서 정상적으로 이미지가 업로드됐는지 확인한다.

아래는 docker login 시 발생했던 오류를 기록해둔다.

login이 됐었는데 어느순간 password를 올바르게 입력해도 에러가 발생한다.

에러를 읽어보니 8.8.8.8이 적혀있어 현재 nameserver를 168.126.63.1로 변경해보고 다시 시도해보았다.

[root@centos7 kube]# docker login 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 (wowjd1375): wowjd1375 Password: Error response from daemon: Get https://registry-1.docker.io/v2/: dial tcp: lookup registry-1.docker.io on 8.8.8.8:53: read udp 192.168.219.100:60940->8.8.8.8:53: i/o timeout

변경했더니 다시 잘 된다.

google에 검색해보니 계정정보가 일치하지 않은 경우 발생하는 에러라는데 비밀번호는 여러번 올바르게 입력했었다.

혹시 동일한 오류가 발생한다면 /etc/resolv.conf에서 nameserver를 변경하고

systemctl restart network 후 재로그인을 시도해보길 바란다.

[root@centos7 kube]# docker login 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 (wowjd1375): wowjd1375 Password: Login Succeeded

from http://public-cloud.tistory.com/41 by ccl(A) rewrite - 2021-07-30 01:26:30