## docker help
- 도커의 명령행 도구는 하위 명령 형태로 구성돼 있기 때문에 docker COMMAND SUBCOMMAND 같은 형태로 사용해야 한다.
```sh
Common Commands:
run Create and run a new container from an image
exec Execute a command in a running container
ps List containers
build Build an image from a Dockerfile
pull Download an image from a registry
push Upload an image to a registry
images List images
login Log in to a registry
logout Log out from a registry
search Search Docker Hub for images
version Show the Docker version information
info Display system-wide information
```
## docker image build
`Dockerfile`에 기술된 구성을 따라 도커 이미지를 생성
```
# docker image build -t 이미지명:[태그] Dockerfile경로
$ docker image build -t exampleecho:latest
```
- 옵션
- -t : `이미지명:[태그]` 형태로 작성한다.
- -f : `docker image build` 명령어는 기본적으로 `Dockerfile`을 찾는다. 특정 파일을 사용하려면 이 옵션을 사용한다.
- `$ docker image build -f Dockerfile-test -t example:latest`
- --pull : 이 옵션을 사용하면 `FROM`에 사용할 베이스 이미지를 강제로 새로 받아온다.
- `$ docker image build --pull=true -t example:latest`
- 빌드 속도 면에서는 조금 불리하다. 실무에서는 latest로 지정하는 것을 피하자
## docker image pull
- `$ docker image pull jenkins:latest`
- 도커이미지를 다운로드 한다.
## docker image ls
- 다운로드된 도커 이미지 목록을 보여준다.
- `$ docker image ls`
- image id와 container id는 다른 것이다. 혼돈하지 말자.
## docker image tag
- 이미지에 태그를 붙일때 사용한다.
- `:latest` 태그는 git의 master 브랜치와 같은 개념이므로 항상 최신의 버전을 가리키도록 하자
- `$ docker image tag exampleecho:latest exampleecho:4.2`
## docker image push
- 도커 이미지를 공유하기 위해 레지스트리에 등록한다.
- `$docker image push 리포지토림명[:태그]`
- 프라이빗 레지스트리를 구축할 수 도 있다.
```
# 로컬에 registry를 하나 만든다.
$ docker run -d -p 5001:5000 --restart always --name registry registry:2`
# 기존 이미지를 tag 명령어를 이용하여 로컬 registry 등록용 이미지를 생성한다.
$ docker image tag exampleecho:latest localhost:5001/exampleecho:latest
# 로컬 registry에 push한다.
$ docker image push localhost:5001/exmampleecho:latest
```
댓글
댓글 쓰기