docker/docker-compose command line

本文详细介绍了Docker的基本命令,如创建、启动、运行容器,管理镜像等,并探讨了Docker Compose的常用命令,如构建、运行、停止服务等。对于Docker初学者和DevOps从业者来说,是理解Docker操作和部署应用的重要参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值