无法下载镜像或速度很慢怎么办?下载方法(例如,要下载 ubuntu 仓库中的 12.04 镜像,可以使用):
$ sudo docker pull dl.dockerpool.com:5000/ubuntu:12.04
之后,修改下tag即可:
$ sudo docker tag dl.dockerpool.com:5000/ubuntu:12.04 ubuntu:12.04
如何退出一个镜像的bash,而不终止它?
按 Ctrl p q。
# 启动一个 bash 终端,允许用户进行交互。
sudo docker run -t -i ubuntu:14.04 /bin/bash
# 列出当前所有正在运行的container
sudo docker ps
# 列出所有的container
sudo docker ps -a
# 列出最近一次启动的container
sudo docker ps -l
# 根据容器名字启动已经停止了的容器
sudo docker start name
# 一个容器之前没有配置端口映射,后面想配置端口映射怎么办?
sudo docker commit container_id tag_name
sudo docker run -i -t -p 127.0.0.1:11111:11111 tag_name
# -v Docker支持挂载宿主机目录,支持宿主机目录和容器之间文件目录进行映射,彼此共享
sudo docker run -d -P --name web -v /webapp:/webapp training/webapp python app.py
# 把本地文件夹/src/webapp挂在到容器中的/opt/webapp目录.宿主机上的文件夹必须是绝对路径,而且当文件夹不存在时会自动创建.
sudo docker -d -P --name web -v /src/webapp:/opt/webapp training/webapp python app.py
# 查看docker版本
sudo docker version
# 显示docker系统的信息
sudo docker info
# 检索image
sudo docker search image_name
# 下载image
sudo docker pull image_name
# 列出镜像列表; -a, --all=false Show all images; --no-trunc=false Don't truncate output; -q, --quiet=false Only show numeric IDs
sudo docker images
# 删除一个或者多个镜像; -f, --force=false Force; --no-prune=false Do not delete untagged parents
sudo docker rmi image_name
# 显示一个镜像的历史; --no-trunc=false Don't truncate output; -q, --quiet=false Only show numeric IDs
sudo docker history image_name
# 在容器中安装新的程序
sudo docker run image_name apt-get install -y app_name
# 删除所有容器
sudo docker rm `docker ps -a -q`
# 删除单个容器; -f, --force=false; -l, --link=false Remove the specified link and not the underlying container; -v, --volumes=false Remove the volumes associated to the container
sudo docker rm Name/ID
# 停止、启动、杀死一个容器
sudo docker stop Name/ID
sudo docker start Name/ID
sudo docker kill Name/ID
# 从一个容器中取日志; -f, --follow=false Follow log output; -t, --timestamps=false Show timestamps
sudo docker logs Name/ID
# 列出一个容器里面被改变的文件或者目录,list列表会显示出三种事件,A 增加的,D 删除的,C 被改变的
sudo docker diff Name/ID
# 显示一个运行的容器里面的进程信息
sudo docker top Name/ID
# 从容器里面拷贝文件/目录到本地一个路径
sudo docker cp Name:/container_path to_path
sudo docker cp ID:/container_path to_path
# 重启一个正在运行的容器; -t, --time=10 Number of seconds to try to stop for before killing the container, Default=10
sudo docker restart Name/ID
# 附加到一个运行的容器上面; --no-stdin=false Do not attach stdin; --sig-proxy=true Proxify all received signal to the process
sudo docker attach ID
当需要把一台机器上的镜像迁移到另一台机器的时候,需要保存镜像与加载镜像。
# 保存镜像到一个tar包; -o, --output="" Write to an file
sudo docker save image_name -o file_path
# 加载一个tar包格式的镜像; -i, --input="" Read from a tar archive file
sudo docker load -i file_path
# 机器a
sudo docker save image_name > /home/save.tar
# 使用scp将save.tar拷到机器b上,然后:
sudo docker load < /home/save.tar
登录registry server(login)
# 登陆registry server; -e, --email="" Email; -p, --password="" Password; -u, --username="" Username
sudo docker login
# 发布docker镜像
sudo docker push new_image_name
根据Dockerfile 构建出一个容器
#build
--no-cache=false Do not use cache when building the image
-q, --quiet=false Suppress the verbose output generated by the containers
--rm=true Remove intermediate containers after a successful build
-t, --tag="" Repository name (and optionally a tag) to be applied to the resulting image in case of success
sudo docker build -t image_name Dockerfile_path
$ sudo docker pull dl.dockerpool.com:5000/ubuntu:12.04
之后,修改下tag即可:
$ sudo docker tag dl.dockerpool.com:5000/ubuntu:12.04 ubuntu:12.04
如何退出一个镜像的bash,而不终止它?
按 Ctrl p q。
# 启动一个 bash 终端,允许用户进行交互。
sudo docker run -t -i ubuntu:14.04 /bin/bash
# 列出当前所有正在运行的container
sudo docker ps
# 列出所有的container
sudo docker ps -a
# 列出最近一次启动的container
sudo docker ps -l
# 根据容器名字启动已经停止了的容器
sudo docker start name
# 一个容器之前没有配置端口映射,后面想配置端口映射怎么办?
sudo docker commit container_id tag_name
sudo docker run -i -t -p 127.0.0.1:11111:11111 tag_name
# -v Docker支持挂载宿主机目录,支持宿主机目录和容器之间文件目录进行映射,彼此共享
sudo docker run -d -P --name web -v /webapp:/webapp training/webapp python app.py
# 把本地文件夹/src/webapp挂在到容器中的/opt/webapp目录.宿主机上的文件夹必须是绝对路径,而且当文件夹不存在时会自动创建.
sudo docker -d -P --name web -v /src/webapp:/opt/webapp training/webapp python app.py
# 查看docker版本
sudo docker version
# 显示docker系统的信息
sudo docker info
# 检索image
sudo docker search image_name
# 下载image
sudo docker pull image_name
# 列出镜像列表; -a, --all=false Show all images; --no-trunc=false Don't truncate output; -q, --quiet=false Only show numeric IDs
sudo docker images
# 删除一个或者多个镜像; -f, --force=false Force; --no-prune=false Do not delete untagged parents
sudo docker rmi image_name
# 显示一个镜像的历史; --no-trunc=false Don't truncate output; -q, --quiet=false Only show numeric IDs
sudo docker history image_name
# 在容器中安装新的程序
sudo docker run image_name apt-get install -y app_name
# 删除所有容器
sudo docker rm `docker ps -a -q`
# 删除单个容器; -f, --force=false; -l, --link=false Remove the specified link and not the underlying container; -v, --volumes=false Remove the volumes associated to the container
sudo docker rm Name/ID
# 停止、启动、杀死一个容器
sudo docker stop Name/ID
sudo docker start Name/ID
sudo docker kill Name/ID
# 从一个容器中取日志; -f, --follow=false Follow log output; -t, --timestamps=false Show timestamps
sudo docker logs Name/ID
# 列出一个容器里面被改变的文件或者目录,list列表会显示出三种事件,A 增加的,D 删除的,C 被改变的
sudo docker diff Name/ID
# 显示一个运行的容器里面的进程信息
sudo docker top Name/ID
# 从容器里面拷贝文件/目录到本地一个路径
sudo docker cp Name:/container_path to_path
sudo docker cp ID:/container_path to_path
# 重启一个正在运行的容器; -t, --time=10 Number of seconds to try to stop for before killing the container, Default=10
sudo docker restart Name/ID
# 附加到一个运行的容器上面; --no-stdin=false Do not attach stdin; --sig-proxy=true Proxify all received signal to the process
sudo docker attach ID
当需要把一台机器上的镜像迁移到另一台机器的时候,需要保存镜像与加载镜像。
# 保存镜像到一个tar包; -o, --output="" Write to an file
sudo docker save image_name -o file_path
# 加载一个tar包格式的镜像; -i, --input="" Read from a tar archive file
sudo docker load -i file_path
# 机器a
sudo docker save image_name > /home/save.tar
# 使用scp将save.tar拷到机器b上,然后:
sudo docker load < /home/save.tar
登录registry server(login)
# 登陆registry server; -e, --email="" Email; -p, --password="" Password; -u, --username="" Username
sudo docker login
# 发布docker镜像
sudo docker push new_image_name
根据Dockerfile 构建出一个容器
#build
--no-cache=false Do not use cache when building the image
-q, --quiet=false Suppress the verbose output generated by the containers
--rm=true Remove intermediate containers after a successful build
-t, --tag="" Repository name (and optionally a tag) to be applied to the resulting image in case of success
sudo docker build -t image_name Dockerfile_path