[Record] Use docker to create custom container operations on Mac

, download docker and install it

https://www.docker.com/get-started/

2. Check the docker version

(base) linql@localhost ~ % docker --version
Docker version 24.0.2, build cb74dfc

3. Install Ubuntu on docker

(1) First retrieve the Ubuntu version

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) Install the latest version of ubuntu

docker pull ubuntu

(3) Install the specified version of ubuntu

docker pull ubuntu:18.04

(4) View installed images

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. Create a folder on the desktop

And, create two files:

(1)Dockerfile

(2)app.py

How to create:

<1>Under the docker_Demo file, use "Go2Shell" to open it

 

<2>Create a Dockerfile file and enter:

vim Dockerfile

Then enter the corresponding content:

# Base images基础镜像
FROM ubuntu:18.04

#MAINTAINER 维护者信息
MAINTAINER 3*****[email protected]

#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"]

 Click: esc, enter: [:wq] to exit and save.

<3>Create the app.py file and enter:

vim app.py

Then enter the corresponding content:

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)

 Click: esc, enter: [:wq] to exit and save.

5. Create containers based on images

docker build -t linql/web01:1.0 . -f Dockerfile

linql/web01:1.0, file path, 1.0 is the version number

【.】, indicating the same level directory

6. Run

docker run -d -p 80:8000 linql/web01:1.0

 7. Result display

docker other instructions

(1)docker ps

(2)docker ps -a 

(3) docker rm container ID 

Guess you like

Origin blog.csdn.net/qq_23938507/article/details/132544558