docker/docker-compose command
docker
- docker container [command]
create — Create a container from an image.
start — Start an existing container.
run — Create a new container and start it.
ls — List running containers.
inspect — See lots of info about a container.
logs — Print logs.
stop — Gracefully stop running container.
kill —Stop main process in container abruptly.
rm— Delete a stopped container. - docker image [command]
build — Build an image.
push — Push an image to a remote registry.
ls — List images.
history — See intermediate image info.
inspect — See lots of info about an image, including the layers.
rm — Delete an image.
docker example
docker container run -i -t -p 1000:8000 --rm my_image
- -i is short for --interactive. Keep STDIN open even if unattached.
- -tis short for–tty. Allocates a pseudo terminal that connects your terminal with the container’s STDIN and STDOUT.
- -p is short for --port. The port is the interface with the outside world.1000:8000 maps the Docker port 8000 to port 1000 on your machine.
- –rm Automatically delete the container when it stops running.
List item
docker container run -d my_image
- -d is short for --detach. Run the container in the background. Allows you to use the terminal for other commands while your container runs.
docker container ls -a -s
- -a is short for -all. List all containers (not just running ones).
- -s is short for --size. List the size for each container.
docker container inspect my_container
- See lots of info about a container.
docker container logs my_container
- Print a container’s logs.
docker container stop my_container
docker container kill my_container
docker container kill $(docker ps -q)
- stop is to stop one or more containers gracefully
- kill is to stop one or more containers
- last with script is to kill all running containers
docker container rm my_container
docker container rm $(docker ps -q)
- delete and delete all containers (which are not running)
docker image build -t my_repo/my_image:my_tag .
- To create an image, -t is short for tag. Tells docker to tag the image with the provided tag. In this case my_tag .
- be careful of last ‘.’, which means current location(dir)
docker-compose
docker-compose [COMMAND] --help
- help to get all command inspect
docker-compose [options] [COMMAND] [ARGS…]
- common docker-compose command
build
- build or rebuild the service
kill
logs
ps
port
rm
run
- all these are quite common
docker-compose up -d
- up is to build and run all services, combine all output from different containers.
- -d mean run it as background, won’t stop when exit
docker-compose down
- stop and remove containers.
本文详细介绍了Docker的基本命令,如创建、启动、运行容器,管理镜像等,并探讨了Docker Compose的常用命令,如构建、运行、停止服务等。对于Docker初学者和DevOps从业者来说,是理解Docker操作和部署应用的重要参考。
2197

被折叠的 条评论
为什么被折叠?



