Docker

Docker
docker image rm <image_id> # delete a image. -f force

CLI

docker run

从 image 创建一个新的 container 并启动。Docs

# CMD 默认直接执行,覆盖 Dockerfile里的 CMD 配置。但如果Dockerfile里定义了ENTRYPOINT, 则CMD会作为附加参数传给ENTRYPOINT
docker run <image_id> [CMD]
  • -d : detech。以后台(持久)进程方式启动container。
  • -i : interactive。Keep STDIN open even if not attached
  • -t : Allocate a pseudo-TTY
    • -it : 常常合用 -it 参数。Assign name and allocate pseudo-TTY。可用于进入container里的shell交互环境
  • -e "ENV=value" : 设置环境变量。可多次使用。
  • -p 0.0.0.0:8080:80/tcp : 将container里的80端口映射到主机0.0.0.0的8080端口。支持 tcp / udp。可多次使用。绑定的IP地址部分可选(默认 "0.0.0.0:")

docker build

docker build -t name[:tag] context

context 根目录下需要有 Dockerfile

context 参数可以使用 github / bitbucket 的远程 URL

Others

  • docker stop container_id : 结束 container (并销毁之?)。

Tips

Exploring Docker container's file system

https://stackoverflow.com/questions/20813486/exploring-docker-containers-file-system

snapshoting

# find ID of your running container:
docker ps

# create image (snapshot) from container filesystem
docker commit 12345678904b5 mysnapshot

# explore this filesystem using bash (for example)
docker run -it mysnapshot /bin/bash

docker exec (for docker 1.3+)

"docker exec" command run new process in already running container (container must have PID 1 process running already). You can run /bin/bash to explore container state:

docker exec -it mycontainer /bin/bash

Publish local image to Docker Cloud

docker login # 根据提示输入 Docker Cloud 用户名/密码,假设用户名为 user
docker tag <image_name> user/abc
docker push user/abc

Solutions

"[graphdriver] prior storage driver "aufs" failed: driver not supported"

https://askubuntu.com/questions/870889/cant-start-docker-on-ubuntu-16-04-with-driver-not-supported-error/870890

The problem is that aufs is not supported on kernel 4.0.x

Quick Solutions (removing aufs from docker): rm -rf /var/lib/docker/aufs

But this will delete all existing AUFS containers.


Last update: 2018-12-22 01:45:41 UTC