Docker 项目的目标是实现轻量级的操作系统虚拟化解决方案。Docker 的基础是 Linux 容器(LXC)等技术。其主要目的是保证一致的运行环境,以及更快速的交付与部署。


镜像:镜像(Image)就是一堆只读层(read-only layer)的统一视角。

容器:容器(container)的定义和镜像(image)几乎一模一样,也是一堆层的统一视角,唯一区别在于容器的最上面那一层是可读可写的。容器 = 镜像 + 可读层。


搜索镜像:docker search 在docker index中搜索image

下载镜像:docker pull 从docker registry server 中下拉image

上传镜像:docker push NAME[:TAG]

镜像有关的其它,命令均可以通过 docker image --help 查看

build Build an image from a Dockerfile
history Show the history of an image
import Import the contents from a tarball to create a filesystem image
inspect Display detailed information on one or more images
load Load an image from a tar archive or STDIN
ls List images
prune Remove unused images
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rm Remove one or more images
save Save one or more images to a tar archive (streamed to STDOUT by default)
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE


镜像有关的其它,命令均可以通过 docker container --help 查看

attach Attach local standard input, output, and error streams to a running container
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
exec Run a command in a running container
export Export a container's filesystem as a tar archive
inspect Display detailed information on one or more containers
kill Kill one or more running containers
logs Fetch the logs of a container
ls List containers
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
prune Remove all stopped containers
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
run Run a command in a new container
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
wait Block until one or more containers stop, then print their exit codes


使用镜像创建容器 docker container run -d -p localport:containerport

重新进入容器命令 docker container exec -it /bin/bash

Dockerfile 创建自定义镜像

FROM ubuntu:20.04
LABEL description='Flask project for flask'

RUN apt-get update
#RUN apt-get upgrade -y

# Install vim
RUN apt-get install -y vim

# Install pip
RUN apt-get install -y python3-pip
RUN pip3 install flask==1.1.2 -i && pip3 install gunicorn==20.1.0 -i

COPY /flask /flask
WORKDIR /flask

# 暴露的容器端口
EXPOSE 7080 7081
# 必须用中括号写,直接写启动语句在执行后会自动关闭容器
#CMD ["python3", "./"]
CMD gunicorn -c flasktext:app