root@ubuntu:~# mkdir /docker
root@ubuntu:~# cd /docker
root@ubuntu:/docker#
root@ubuntu:/docker# vi Dockerfile
FROM nginx:latest
FROM
Base image.
custom image는 Base image 위에 layer를 추가하는 형식으로 제작된다.
root@ubuntu:/docker# docker build -t my_nginx:1.0 .
root@ubuntu:/docker# docker build -t my_nginx:1.0 .
Sending build context to Docker daemon 2.048kB
Step 1/1 : FROM nginx:latest
---> 88736fe82739
Successfully built 88736fe82739
Successfully tagged my_nginx:1.0
-t
tag 지정
1.0은 version이며, 내가 맘대로 정하는 부분이다.
.
파일 경로가 현재 경로의 Dockerfile이 아니면 파일 경로를 명시해야 한다. 이 때 경로는 directory로 주어져야 한다.
root@ubuntu:/docker# docker images
root@ubuntu:/docker# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd latest 8653efc8c72d 2 weeks ago 145MB
my_nginx 1.0 88736fe82739 2 weeks ago 142MB
nginx latest 88736fe82739 2 weeks ago 142MB
centos 7 eeb6ee3f44bd 14 months ago 204MB
root@ubuntu:/docker# docker run -d --name my_nginx -p 555:80 my_nginx:1.0
root@ubuntu:/docker# docker run -d --name my_nginx -p 555:80 my_nginx:1.0
339ac219b3a7bd0c91917407f32c2181be15a59c09854b70f8c3bc5b7e828152
root@ubuntu:/docker# curl localhost:555
root@ubuntu:/docker# curl localhost:555
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="<http://nginx.org/>">nginx.org</a>.<br/>
Commercial support is available at
<a href="<http://nginx.com/>">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
root@ubuntu:/docker# docker tag my_nginx:1.0 beyondthemist/my_nginx:1.0 root@ubuntu:/docker# docker image ls
root@ubuntu:/docker# docker tag my_nginx:1.0 beyondthemist/my_nginx:1.0
root@ubuntu:/docker# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd latest 8653efc8c72d 2 weeks ago 145MB
beyondthemist/my_nginx 1.0 88736fe82739 2 weeks ago 142MB
my_nginx 1.0 88736fe82739 2 weeks ago 142MB
nginx latest 88736fe82739 2 weeks ago 142MB
centos 7 eeb6ee3f44bd 14 months ago 204MB
내가 만든 docker image에 tag를 붙인다.
root@ubuntu:/docker# docker push beyondthemist/my_nginx:1.0
root@ubuntu:/docker# docker push beyondthemist/my_nginx:1.0
The push refers to repository [[docker.io/beyondthemist/my_nginx](<http://docker.io/beyondthemist/my_nginx>)]
6cffb086835a: Mounted from library/nginx
e2d75d87993c: Mounted from library/nginx
5a5bafd53f76: Mounted from library/nginx
f86e88a471f4: Mounted from library/nginx
f7ed3797e296: Mounted from library/nginx
ec4a38999118: Mounted from library/nginx
1.0: digest: sha256:6ad8394ad31b269b563566998fd80a8f259e8decf16e807f8310ecc10c687385 size: 1570
방금 tag를 붙인 docker image를 내 repository에 업로드한다.
이 작업을 하려면 Docker hub에 로그인이 되어 있어야 한다.
→ root@ubuntu:/docker# docker login
repository 삭제
밑에 [Delete repository] 버튼 누르고 이름 한 번 더 입력하면 삭제됨
root@ubuntu:/docker# vi Dockerfile
FROM nginx:latest
COPY index.html /usr/share/nginx/html/index.html
WORKDIR /usr/share/nginx.html
FROM
base image
COPY <SRC> <DEST>
SRC
를 DEST
로 복사한다
WORKDIR
working directory 지정
root@ubuntu:/docker# docker image rm -f my_nginx:1.0
root@ubuntu:/docker# docker image rm -f beyondthemist/my_nginx:1.0
root@ubuntu:/docker# docker image rm -f my_nginx:1.0
Untagged: my_nginx:1.0
root@ubuntu:/docker# docker image rm -f beyondthemist/my_nginx:1.0
Untagged: beyondthemist/my_nginx:1.0
Untagged: beyondthemist/my_nginx@sha256:6ad8394ad31b269b563566998fd80a8f259e8decf16e807f8310ecc10c687385
여기서 표시되는 beyondthemist/my_nginx:1.0
와 ****Docker hub에서 표시되는 그것은 별개다.
root@ubuntu:/docker# docker build -t my_nginx:1.1 .
root@ubuntu:/docker# docker build -t my_nginx:1.1 .
Sending build context to Docker daemon 3.072kB
Step 1/3 : FROM nginx:latest
---> 88736fe82739
Step 2/3 : COPY index.html /usr/share/nginx/html/index.html
---> afb5883ff029
Step 3/3 : WORKDIR /usr/share/nginx.html
---> Running in f0795a3831a7
Removing intermediate container f0795a3831a7
---> 8a3991c34dae
Successfully built 8a3991c34dae
Successfully tagged my_nginx:1.1
root@ubuntu:/docker# docker run -dp 999:80 --name my_nginx my_nginx:1.1
root@ubuntu:/docker# docker run -dp 999:80 --name my_nginx my_nginx:1.1
7d04b3d9dba9aac446fc95a9da62ddf9136508e283a3637191927bd72189fa68
root@ubuntu:/docker# curl localhost:999
root@ubuntu:/docker# curl localhost:999
dockerfile