、下载docker并安装
https://www.docker.com/get-started/
2、查看docker版本
(base) linql@localhost ~ % docker --version
Docker version 24.0.2, build cb74dfc
3、在docker上安装Ubuntu
(1)先检索Ubuntu版本
docker search ubuntu
(base) linql@localhost ~ % docker search ubuntu
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Ubuntu is a Debian-based Linux operating sys… 16327 [OK]
websphere-liberty WebSphere Liberty multi-architecture images … 296 [OK]
open-liberty Open Liberty multi-architecture images based… 61 [OK]
neurodebian NeuroDebian provides neuroscience research s… 103 [OK]
ubuntu-debootstrap DEPRECATED; use "ubuntu" instead 52 [OK]
ubuntu-upstart DEPRECATED, as is Upstart (find other proces… 115 [OK]
ubuntu/nginx Nginx, a high-performance reverse proxy & we… 98
ubuntu/squid Squid is a caching proxy for the Web. Long-t… 65
ubuntu/cortex Cortex provides storage for Prometheus. Long… 4
ubuntu/apache2 Apache, a secure & extensible open-source HT… 60
ubuntu/kafka Apache Kafka, a distributed event streaming … 32
ubuntu/mysql MySQL open source fast, stable, multi-thread… 52
ubuntu/bind9 BIND 9 is a very flexible, full-featured DNS… 59
ubuntu/prometheus Prometheus is a systems and service monitori… 49
ubuntu/zookeeper ZooKeeper maintains configuration informatio… 9
ubuntu/postgres PostgreSQL is an open source object-relation… 31
ubuntu/redis Redis, an open source key-value store. Long-… 19
ubuntu/grafana Grafana, a feature rich metrics dashboard & … 9
ubuntu/memcached Memcached, in-memory keyvalue store for smal… 5
ubuntu/dotnet-deps Chiselled Ubuntu for self-contained .NET & A… 9
ubuntu/dotnet-aspnet Chiselled Ubuntu runtime image for ASP.NET a… 11
ubuntu/prometheus-alertmanager Alertmanager handles client alerts from Prom… 9
ubuntu/dotnet-runtime Chiselled Ubuntu runtime image for .NET apps… 10
ubuntu/cassandra Cassandra, an open source NoSQL distributed … 2
ubuntu/telegraf Telegraf collects, processes, aggregates & w… 4
(2)安装最新版的ubuntu
docker pull ubuntu
(3)安装指定版本的ubuntu
docker pull ubuntu:18.04
(4)查看已经安装的镜像
docker images
(base) linql@localhost ~ % docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
linql/web01 1.0 8a5063fd0e4d 3 hours ago 495MB
ubuntu 18.04 f9a80a55f492 3 months ago 63.2MB
ambassador/telepresence-docker-extension 1.0.8 bb2143440bbd 3 months ago 528MB
ambassador/telepresence-docker-runtime 1.0.8 a1a178ca4417 3 months ago 21.3MB
python latest 0a6cd0db41a4 3 months ago 920MB
4、在桌面上创建一个文件夹
并,创建两个文件:
(1)Dockerfile
(2)app.py
创建方式:
<1>在docker_Demo文件下,使用“Go2Shell”打开
<2>创建Dockerfile文件,输入:
vim Dockerfile
然后输入对应内容:
# Base images基础镜像
FROM ubuntu:18.04
#MAINTAINER 维护者信息
MAINTAINER 3*****0@qq.com
#RUN 执行以下命令
RUN apt update
RUN apt install python3 python3-pip -y
USER root
RUN python3 -m pip install --no-cache-dir flask
RUN mkdir -p /data/www
#COPY 拷贝文件至工作目录
COPY app.py /data/www/app.py
#工作目录
WORKDIR /data/www/
#容器启动时执行命令
CMD ["python3","app.py"]
点:esc,输入:[:wq],即可退出并保存。
<3>创建app.py文件,输入:
vim app.py
然后输入对应内容:
from flask import Flask
app = Flask(__name__)
@app.route("/index")
def index():
return "欢迎光临"
if __name__ =="__main__":
app.run(host="0.0.0.0",port=8000)
点:esc,输入:[:wq],即可退出并保存。
5、基于镜像创建容器
docker build -t linql/web01:1.0 . -f Dockerfile
linql/web01:1.0,文件路径,1.0是版本号
【.】,表示同级目录
6、运行
docker run -d -p 80:8000 linql/web01:1.0
7、结果展示
docker 其他指令
(1)docker ps
(2)docker ps -a
(3)docker rm 容器ID