【记录】在Mac上使用docker 创建自定义容器操作

、下载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 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Docker是一个开源的容器化平台,可以帮助开发者将应用程序打包成轻量级、可移植的容器,方便在不同的环境中进行部署和运行。 Docker容器是指一个独立的运行环境,包含了应用程序及其依赖的库、框架、配置等,可以在不同的操作系统、服务器、云平台上进行部署和运行。 Docker仓库则是用于存储和分享Docker镜像的中央存储库,类似于代码版本控制系统中的代码仓库,可以方便地管理和分享Docker镜像。 下面是Docker容器Docker仓库的安装和使用步骤: 1. 安装Docker 在Linux系统中,可以通过以下命令安装Docker: ``` sudo apt-get update sudo apt-get install docker.io ``` 在Windows和Mac OS X系统中,需要先下载安装Docker Desktop应用程序,然后运行即可。 2. 运行Docker容器 使用Docker运行容器需要用到Docker镜像,可以通过以下命令从Docker Hub上下载并运行一个Nginx Web服务器的镜像: ``` docker run -d -p 80:80 nginx ``` 该命令会在后台运行一个Nginx容器,并将容器的80端口映射到主机的80端口,可以通过访问主机IP地址查看Nginx欢迎页面。 3. 创建Docker镜像 如果需要自定义应用程序的运行环境,可以通过Dockerfile文件定义镜像构建规则,然后使用Docker命令构建并推送到Docker仓库: ``` # Dockerfile文件内容 FROM ubuntu:18.04 RUN apt-get update && apt-get install -y nginx CMD ["nginx", "-g", "daemon off;"] # 构建镜像 docker build -t my-nginx . # 推送镜像到Docker仓库 docker push my-nginx ``` 4. 使用Docker仓库 Docker仓库可以用于存储和分享Docker镜像,可以通过以下命令从Docker仓库中下载镜像并运行容器: ``` docker pull my-nginx docker run -d -p 80:80 my-nginx ``` 以上就是Docker容器Docker仓库的安装和使用步骤,希望对你有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值