Docker Commands
- Building an image
docker image build -t example/echo:latest .
- Running an image (background)
docker container run -d example/echo:latest
- List of images running
docker container ls
- Stop image
--filter
option was used to print the containers that match the condition-q
option was used to print the id only
docker container stop $(docker container ls --filter "ancestor=example/echo" -q)
- Running an image on the background with port forwarding
docker container run -d -p 9000:8080 example/echo:latest
- Host port can be omitted
- Then some open port will be automatically mapped
- Can check mapped port with
docker container ls
docker container run -d -p 8080 example/echo:latest
- Using tags on image
docker image tag example/echo:latest example/echo:0.1.0
docker image ls
- Giving names to container
- Use the
--name
option - Then you can stop the container with name
- Use the
docker container run -t -d --name echo example/echo:latest
docker container stop echo
- Restarting a stopped container
- Can use name or container id
docker container restart echo
- Removing a container
- Can use name or container id
docker container rm echo
- Remove all exited container
docker container rm $(docker container ls --filter "status=exited" -q)
- Checking stdout of some container
- Can use name or container id
- Can be used for debugging
docker container logs -f echo
- Executing commands in a container
docker container exec echo [command]
- Using a terminal (as if connected to ssh)
docker container exec -it [name or id] sh
- Copy files between container and host
- Can be used to move files created during execution and check them (usually for debugging purposes)
docker container cp [options] [container id/name]:[original file] [target file]
docker container cp [options] [host original file] [container id/name]:[target file]
'Computer Science > Web' 카테고리의 다른 글
1년 뒤 다시 찾아본 인터넷 편지 사이트 (4) | 2021.05.03 |
---|---|
육군훈련소에서 인터넷 편지 편하게 받기 (0) | 2020.06.13 |
Tistory 이주 (0) | 2020.01.10 |
github.io 사이트 설정 - 2 (0) | 2020.01.10 |
github.io 사이트 설정 (0) | 2020.01.10 |
댓글