可以参考这里: 说的还是比较明确的

http://www.runoob.com/docker/docker-run-command.html


1,

FROM alpine:latest
RUN apk add --update htop && rm -rf /var/cache/apk/*
CMD ["htop"]


docker build -t myhtop .
docker run -it --rm --pid=host myhtop


Joining another container’s pid namespace can be used for debugging that container.

$ docker run -it --pid=container:my-redis my_strace_docker_image bash
$ strace -p 1

2.管理网络
$ docker network ls


NETWORK ID          NAME                DRIVER
7fca4eb8c647        bridge              bridge
9f904ee27bf5        none                null
cf03ee007fb4        host                host


$ docker run -itd --name=container1 busybox
$ docker run -itd --name=container2 busybox
$ docker network inspect bridge

3,管理hosts
$ docker run -it --add-host db-static:86.75.30.9 ubuntu cat /etc/hosts
172.17.0.22     09d03f76bf2c
fe00::0         ip6-localnet
ff00::0         ip6-mcastprefix
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters
127.0.0.1       localhost
::1	            localhost ip6-localhost ip6-loopback
86.75.30.9      db-static

3,过滤各种信息
$ docker inspect -f "{{ .State.StartedAt }}" my-container
# 2015-03-04T23:47:07.691840179Z


4,restart

$ docker run --restart=always redis
$ docker run --restart=on-failure:10 redis

5,限制资源
$ docker run -it -m 300M ubuntu:14.04 /bin/bash
$ docker run -it -m 300M --memory-swap 1G ubuntu:14.04 /bin/bash

6,健康检查
$ docker run --name=test -d \
    --health-cmd='stat /etc/passwd || exit 1' \
    --health-interval=2s \
    busybox sleep 1d
$ sleep 2; docker inspect --format='{{.State.Health.Status}}' test
healthy
$ docker exec test rm /etc/passwd
$ sleep 2; docker inspect --format='{{json .State.Health}}' test

7,指定工作目录
[root@lanny ~]# docker run -it --rm -w=/tmp busybox
/tmp # 

8,指定env
 docker run -e "deep=purple" --rm ubuntu /bin/bash -c export

9, --expose 抛出端口







Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐