Skip to content

Latest commit

 

History

History
104 lines (79 loc) · 1.83 KB

docker.md

File metadata and controls

104 lines (79 loc) · 1.83 KB
title category layout
Docker CLI
Devops
default-ad

管理镜像

从 Dockerfile 创建一个 镜像:

docker build [options] .
  -t "app/container_name"    # name

镜像中运行一条命令:

docker run [options] IMAGE
  # see `docker create` for options

管理容器

从一个镜像创建一个容器:

docker create [options] IMAGE
  -a, --attach               # attach stdout/err
  -i, --interactive          # attach stdin (interactive)
  -t, --tty                  # pseudo-tty
      --name NAME            # name your image
  -p, --publish 5000:5000    # port map
      --expose 5432          # expose a port to linked containers
  -P, --publish-all          # publish all ports
      --link container:alias # linking
  -v, --volume `pwd`:/app    # mount (absolute paths needed)
  -e, --env NAME=hello       # env vars
$ docker create --name app_redis_1 \
  --expose 6379 \
  redis:3.0.2

在一个容器中运行:

docker exec [options] CONTAINER COMMAND
  -d, --detach        # run in background
  -i, --interactive   # stdin
  -t, --tty           # interactive
$ docker exec app_web_1 tail logs/development.log
$ docker exec -t -i app_web_1 rails c

启动/停止一个容器:

docker start [options] CONTAINER
  -a, --attach        # attach stdout/err
  -i, --interactive   # attach stdin

docker stop [options] CONTAINER

管理容器:

$ docker ps
$ docker ps -a
$ docker kill $ID

管理中

管理镜像:

$ docker images
  REPOSITORY   TAG        ID
  ubuntu       12.10      b750fe78269d
  me/myapp     latest     7b2431a8d968

$ docker images -a   # also show intermediate

删除镜像:

docker rmi b750fe78269d

资源