// webserver 컨테이너를 web01이라는 이름의 이미지로 생성 [root@localhost ~]# docker container commit webserver web01:v1.0 sha256:d0970224581282ec34ad6093561ee43a4e31955772c4d97fe35148ff22545d9b
// 생성한 이미지를 도커 허브에 올리기 위해 tag를 달아준다 (hyeyeon9813은 내 도커허브 계정) [root@localhost ~]# docker image tag web01:v1.0 hyeyeon9813/web01:v1.0
// 이미지 생성 확인 - web01이미지와 hyeyeon9813/web01이라는 별칭의 이미지 생성 [root@localhost ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE hyeyeon9813/web01 v1.0 d09702245812 48 seconds ago 133 MB web01 v1.0 d09702245812 48 seconds ago 133 MB docker.io/nginx latest 298ec0e28760 6 days ago 133 MB
// 도커 자격증명을 위한 로그인 [root@localhost ~]# 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: hyeyeon9813 Password: Login Succeeded
// 도커허브에 업로드 (**태그 꼭 붙여주기) [root@localhost ~]# docker image push hyeyeon9813/web01:v1.0 The push refers to a repository [docker.io/hyeyeon9813/web01] 58bfe7dd4689: Pushed d9eb91d66e2a: Mounted from library/nginx ae1f545e4c08: Mounted from library/nginx c20672db3628: Mounted from library/nginx 4cbb728cd302: Mounted from library/nginx 9eb82f04c782: Mounted from library/nginx v1.0: digest: sha256:eead984571de4dc8a2c8f2b26ddb657a2e86aec331eea43dac2bd3d3d3468c0d size: 1570
도커 허브
개발자 - centOS가 아닌 ubuntu 사용중
개발자의 vm을 하나 생성해준다
개발자환경에 도커 설치
johnlee@ubuntu:~$ sudo apt-get update -y [sudo] password for johnlee: johnlee@ubuntu:~$ sudo apt install docker.io -y // 도커 설치 johnlee@ubuntu:~$ systemctl status docker johnlee@ubuntu:~$ sudo apt install -y apache2 // 아파치 서버 설치 johnlee@ubuntu:~$ ss -ant -> 80포트가 열려있는 모습을 확인할 수 있다
// 이미지 확인 johnlee@ubuntu:~$ sudo docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE hyeyeon9813/web01 v1.0 d09702245812 Less than a second ago 133MB
// 컨테이너 실행 johnlee@ubuntu:~$ sudo docker container run --name web01 -d -p 8080:80 hyeyeon9813/web01:v1.0 b4cfa6c0b543328830298e6805c033eac8087d1c649213e1a0e839acfb87b7d0
도커 컨테이너 및 이미지 삭제
// 사용하지 않는 이미지 삭제 [root@localhost ~]# docker image prune -a WARNING! This will remove all images without at least one container associated to them. Are you sure you want to continue? [y/N] y
// 사용중인 이미지 삭제 [root@localhost ~]# docker rmi -f docker.io/nginx Untagged: docker.io/nginx:latest Untagged: docker.io/nginx@sha256:8e10956422503824ebb599f37c26a90fe70541942687f70bbdb744530fc9eba4 -> 아직 컨테이너가 실행중이라 제대로 삭제되지 않는다
// 이미지 다시 삭제 [root@localhost ~]# docker rmi -f 298ec0e28760 Deleted: sha256:298ec0e28760b8eb1aad79711dc29c19041c61d7cf342dd1f445e91f30500549 Deleted: sha256:82a80a581c3c25eec11651e31d5637b7c6dacae2f51dc22998b3168697727bab Deleted: sha256:3e3c87cd680b08d7793d9e5c43117d1d6d2da08bfc1b2d1f1a28555a0224c299 Deleted: sha256:b7639a9a7b8f73c99a76d1dc5777716e230e810a2e737b21b9f36147f69b253b Deleted: sha256:4d7166647e67b04600ec5b94833e79d28b850433136593ea263fa340f3a54b66 Deleted: sha256:9eb82f04c782ef3f5ca25911e60d75e441ce0fe82e49f0dbf02c81a3161d1300 -> 이제 이미지가 제대로 삭제되었다.
도커 컨테이너 생성 및 시작
// 여러개의 컨테이너 생성 [root@localhost ~]# docker run --name web01 -d -p 8080:80 hyeyeon9813/web01:v1.0 [root@localhost ~]# docker run --name web02 -d -p 8282:80 hyeyeon9813/web01:v1.0 [root@localhost ~]# docker run --name web03 -d -p 8383:80 hyeyeon9813/web01:v1.0
// 컨테이너 이름 없이 생성 [root@localhost ~]# docker run -d -p 8181:80 hyeyeon9813/web01:v1.0 [root@localhost ~]# docker run -d -p 8484:80 hyeyeon9813/web01:v1.0
[root@localhost ~]# docker ps
->이름을 지정하지 않고 컨테이너를 생성하면 컨테이너 이름이 임의로 생성된다
// 모든 컨테이너 실행 중지 [root@localhost ~]# docker stop $(docker ps -q)
// 모든 컨테이너 시작 [root@localhost ~]# docker start $(docker ps -aq)