Computer Science/Web
Docker 기초
zxcvber
2020. 2. 27. 18:49
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]