# 创建Dockerfile文件 $ cat > Dockerfile <<EOF FROM python:3.7.4-stretch RUN echo 1 > /tmp/file.txt EOF
# 开始构建 $ docker build . -t my_image
# 再次查看已经有的镜像,简单的一个本地镜像就构建好了. $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE python 3.7.4-stretch b9d77e48a75c 3 weeks ago 940MB my_image latest 860d8f0fd1c4 25 seconds ago 940MB
$ docker run -ti my_image /bin/bash root@9b497582be91:/#
# 新建一个终端, 使用docker ps 可以查看正在运行的容器 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9b497582be91 my_image "/bin/bash" 44 seconds ago Up 43 seconds magical_beaver
1 2 3 4 5 6 7 8 9 10
# docker stop 一个容器
$ docker stop magical_beaver magical_beaver
# 而后docker ps -a可以看到关闭了的容器 $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9b497582be91 my_image "/bin/bash" 2 minutes ago Exited (0) 4 seconds ago magical_beaver