Skip to content

Instantly share code, notes, and snippets.

@xgz123
Last active January 17, 2017 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xgz123/6b149c0852fe0ba484159fe281ac07ac to your computer and use it in GitHub Desktop.
Save xgz123/6b149c0852fe0ba484159fe281ac07ac to your computer and use it in GitHub Desktop.
# 指定了要提交的修改过的容器的ID、目标镜像仓库、镜像名
sudo docker commit 614122c0aabb aoct/apache2
sudo docker commit -m='A new image' --author='xx' 614122c0aabb aoct/apache2
docker tag image_id new_tag # change tag
# install
yum -y install docker-io
# start
systemctl start docker
# or
service docker start
# check
chkconfig docker on
# basic
docker version # version ,deps
docker info # about docker
docker tag image_id name:tag
# usage
docker search ubuntu
docker pull <image>
docker images # 列出所有images
-a # include history
rmi <ID> # delete 1 or more image
rm <ID> # delete container
stop <ID> # stop container
# create container from image
docker run ubuntu /bin/echo hello world
# interactive
docker run -it ubuntu /bin/bash
-i
-t
-rm
-p # port
-v
# containers
docker ps # running
docker ps -l # last
docker ps -a # all(include history)
docker ps -q # ID of last runned container
# start/stop/restart
docker start/stop/restart <container>
docker attach <id> # 连接一个正在运行的容器
docker start -i <id> # 已经存在的
docker run -it <image> /bin/bash # 新创建 -i interactive, -t tty
docker rm <ID>
docker rm `docker ps -a -q` # delete all container
docker ps -a -q | xargs docker rm # same as above
# 你可以
# 挂载宿主目录到镜像里
# 如果不指定宿主目录,则随即生成宿主目录
docker run -it -v /root/Documents/php0117_02:/root/test php:1 /bin/bash
su -c "setenforce 0" # 避免进入容器后,无权限访问此目录, 在宿主机上,下同
chcon -Rt svirt_sandbox_file_t /path/to/volume
# hub.c.163.com/library/php 7.1-apache
docker run -it -v /root/Documents/php0117_02:/var/www/html php:7a /bin/bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment